简体   繁体   English

$ .ajax没有命中控制器

[英]$.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. 作为,你可以看到我是否点击按钮,然后它应该点击控制器并发布表格数据,但是它不起作用。在旧版本的chrome中它可以正常工作。

but yesterday i updated my chrome browser. 但是昨天我更新了Chrome浏览器。 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 我正在使用1.9.1版的jquery

In the ajax operation just add 在ajax操作中只需添加

async: true, 异步:是的,

after

datatype: "json", 数据类型:“ json”,

and that should solve your problem. 那应该可以解决您的问题。 Chrome has issue handling asynchronus calls. Chrome在处理异步调用方面存在问题。

 $("#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. 注意:async参数默认为true,因此您无需通过请求传递该参数,因此删除async:false也可以为您完成此操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM