duke duke - 6 months ago 17
Ajax Question

$.ajax not hitting controller

this is my sample code:

$("#btnPost").click(function (e) {
e.preventDefault();
$.ajax(
{
url: "/api/Flight/FlightList",
type: "Post",
dataType: "json",
data: $('form').serialize() + '&' + $.param({ 'TokenId': $("#pageInitCounter").val() }, true),
// data:"",
success: function (data) {
// implementation here
........................


As, u can see if i click button then it should hit controller and post the form data but it is not working.it was working fine in older chrome version.

but yesterday i updated my chrome browser. after that its not working.
if i try this:

data:"",


then it is hitting controller but with empty data. how it should be done.please someone tell me.

i am using jquery version 1.9.1

Answer

In the ajax operation just add

async: true,

after

datatype: "json",

and that should solve your problem. Chrome has issue handling asynchronus calls.

 $("#btnPost").click(function (e) {
 e.preventDefault();
 $.ajax(
       {
        url: "/api/Flight/FlightList",
        type: "Post",
        dataType: "json",
        async: true,
        data: $('form').serialize() + '&' + $.param({ 'TokenId': $("#pageInitCounter").val() }, true),
       //  data:"",
         success: function (data) {
           // implementation here
          ........................

Note: async parameter is bydefault true, so you need not pass that with request, so removing async: false will also do it for you.

Comments