Pass accepts header parameter to jquery ajax

When I inspect the following code in Chrome Console it shows me a Request header Accept:undefined

jQuery.ajax({
        url: _this.attr('href'),
        accepts: "application/json; charset=utf-8",

    });
});

How do I set accept type as json. I don't want to set a custom header or use beforeSend

Answers


Try this ,

    $.ajax({     
          headers: {          
                 Accept : "text/plain; charset=utf-8",         
                "Content-Type": "text/plain; charset=utf-8"   
  }     
  data: "data",    
  success : function(response) {  
       ...  
   } })

See this post for reference:

Cannot properly set the Accept HTTP header with jQuery


Need Your Help

Lock window to a specific display (winapi)

c++ windows winapi

I want to prevent a window from being moved between monitors by checking for the message WM_MOVE and using the SetWindowPos function to keep the window within the bounds of the display. When I try...

WP7 live tile and push notification

windows-phone-7 push-notification mpns

I am trying to follow Andrea Boschin's example on how to deliver custom tile, blog post available here: http://www.silverlightshow.net/items/Windows-Phone-7-Part-7-Understanding-Push-Notifications....

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.