weixin_33691598 2019-11-14 01:28 采纳率: 0%
浏览 268

jQuery Ajax事件不触发

Going bonkers here and have been using jquery's ajax for years and still can't figure out what is wrong even though there is nothing wrong with the syntax nor the service that it is calling, but the success, error and complete events simply won't fire. I put an alert & a log to console and nothing happens.

$.ajax({
                url: 'DDService.asmx/LoadCountries',
                dataType: 'json',
                method: 'post',
                data: {},
                success: function (data) {
                    alert('success');
                    console.log('success');
                },
                error: function (err) {
                    alert('error');
                    console.log('Error (RetrieveCountriesDD): ' + JSON.stringify(err, null, 2));
                },
                complete: function () {
                    alert('complete');
                    console.log('complete');
                }
            });

I put a code break in the service and it is being called and returning json (like I said, I've done this many times before and this is baffling me) which I've specified, I changed the dataType to text, html and even removed it altogether, still no events fire nor are there any errors anywhere. Using jQuery 3.3.1 - though all other ajax calls all over the place with identical syntax is working (is there something I'm missing here?). Sample of what is returned by the webservice:

[{"T":"United States","V":"1"},{"T":"Canada","V":"2"},{"T":"Afghanistan ","V":"86"},{"T":"Albania ","V":"89"},{"T":"Algeria ","V":"117"},{"T":"American Samoa ","V":"92"},{"T":"Andorra ","V":"90"},{"T":"Angola ","V":"87"},{"T":"Anguilla ","V":"88"}, 

Anyone know what would cause the ajax events to not fire? NOTE: I left out the data parsing portion (to fill a simple dropdown) for brevity since that is not where the problem is - an alert box should show up or something in the console, but nothing at all happens after the service is called.

  • 写回答

1条回答

  • weixin_33737774 2019-11-14 02:01
    关注

    Okay, I'm an idiot. To call the test function, I used a button that was posting back instead of an input type="button".
    Basically, there is a war of 2 different posts happening.
    Firefox will attempt to post to the ajax service, & simultaneously also trying to POST via the button - this yields the odd security error. Chrome will attempt to post to the ajax service, then do the button post (and ignore the alerts). IE is a whore and will only do the button POSTing after everything is run. :) Opera is a lot like IE, but may or may not do the POSTing in the correct order.

    评论

报告相同问题?

悬赏问题

  • ¥15 运筹学中在线排序的时间在线排序的在线LPT算法
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 lammps拉伸应力应变曲线分析
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试,帮帮忙吧