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.

    评论

报告相同问题?

悬赏问题

  • ¥50 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?