jQuery Ajax事件不触发


                    

在这里疯狂地使用了jquery的ajax多年了,尽管语法和所调用的服务没有错,但仍然无法弄清楚出了什么问题,但是成功,错误和完成事件只是 不会开火。 我将警报和日志放入控制台,什么也没发生。</ p>

  $。ajax({
                 网址:“ DDService.asmx / LoadCountries”,
                 dataType:'json',
                 方法:“发布”,
                 数据:{},
                 成功:功能(数据){
                     警报('成功');
                     console.log('成功');
                 },
                 错误:函数(err){
                     警报('错误');
                     console.log('Error(RetrieveCountriesDD):'+ JSON.stringify(err,null,2));
                 },
                 完整:函数(){
                     alert('complete');
                     console.log('complete');
                 }
             });
</ code> </ pre>

我在服务中放了一个代码中断,并调用了它并返回了json(就像我说的,我已经做过很多次了,这让我感到困惑),我已经将dataType更改为text ,html甚至将其完全删除,仍然不会触发任何事件,也不存在任何错误。 使用jQuery 3.3.1-尽管所有其他使用相同语法的ajax调用都可以正常工作(这里是否缺少某些内容?)。 Web服务返回的示例:</ p>

  [{“ T”:“美国”,“ V”:“ 1”},{“ T”:“加拿大”,“ V”:“ 2”},{“ T”:“ 阿富汗“,” V“:” 86“},{” T“:”阿尔巴尼亚“,” V“:” 89“},{” T“:”阿尔及利亚“,” V“:” 117“},{”  T“:”美属萨摩亚“,” V“:” 92“},{” T“:”安道尔“,” V“:” 90“},{” T“:”安哥拉“,” V“:” 87  “},{” T“:”安圭拉“,” V“:” 88“},
</ code> </ pre>

谁知道会导致ajax事件不触发?
注意:为了简洁起见,我省略了数据解析部分(以填充一个简单的下拉列表),因为那不是问题所在-警报框应显示或控制台中出现某些内容,但在调用服务后什么也没有发生。 </ p>
     </ div>

展开原文

原文

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个回答


好的,我是个白痴。 为了调用测试功能,我使用了一个回发的按钮,而不是输入type =“ button”。

基本上,发生了2个不同的帖子之战。

Firefox将尝试发布到ajax服务,同时尝试通过按钮发布-这会产生奇怪的安全错误。
Chrome会尝试发布到ajax服务,然后发布按钮(并忽略警报)。
IE是妓女,只有在所有内容运行完毕后,才执行“发布 </ em>”按钮。 :)
Opera与IE非常相似,但可能会或可能不会以正确的顺序进行发布。</ p>
     </ div>

展开原文

原文

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.

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐