简体   繁体   English

AJAX呼叫未通过成功或错误

[英]AJAX Call does not pass success or error

I've got something I don't understand why it's not working. 我有一些我不明白的东西为什么不起作用。 It's making me go crazy. 这让我发疯。

I've got an AJAX call which does not pass success or error. 我有一个AJAX调用,它不会传递成功或错误。

function getStraatnamen(woonplaatsId) {
    var success = "not set";
    $.ajax({
        url: someURL,
        type: "POST",
        dataType: 'json',
        contentType: 'application/json',
        async: false,
        xhrFields: {
            withCredentials: true
        },
        data: JSON.stringify({"woonplaatsId": woonplaatsId}),
        succes: function (results) {
            success = "true";
            var straatnamen = results.GetStraatNamenResult;
            var StraatNamenArray = [];
            for (var i = 0; i < straatnamen.length; i++) {
                var straatnaam = straatnamen[i];
                StraatNamenArray.push({ text: straatnaam.naamField, value: straatnaam.idField });
            }
            console.log(StraatNamenArray);
            straatnamenCombobox.setDataSource(StraatNamenArray);
            straatnamenCombobox.bind("change", change_straatnaam);

        },
        error: function (error) {
            success = "false";
            console.log(error);
        }
    });
    alert(success);
}

So when this function starts, I set a succes var to "not set". 因此,当此函数启动时,我将成功var设置为“ not set”。 I've set the request async to false so the variable can be changed during success or error. 我已将请求异步设置为false,以便在成功或错误期间可以更改变量。 I've got some console.log for success and error. 我有一些console.log用于成功和错误。

But it does not pass any of them, no logs, and the alert shows "not set". 但是它没有通过任何日志,没有日志,并且警报显示“未设置”。

If I look in the browsers network list and in Fiddler, I see the complete result, so the ajax call is made successfully, but it doesn't pass the success or error. 如果在浏览器的网络列表和Fiddler中查看,则会看到完整的结果,因此ajax调用已成功完成,但未传递成功或错误。

Does any one know why this thing is weird? 有谁知道为什么这件事很奇怪?

Thanx. 感谢名单。

You've spelt "success" as "succes" in your JQUERY. 您在JQUERY中将“成功”拼写为“成功”。

Change the line 换线

 succes: function (results) {

to

 success: function (results) {

Your script probably works, but you got a misprint. 您的脚本可能有效,但是打印错误。 field "success", two 'S' at the end. 字段“成功”,两个“ S”结尾。 :) :)

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

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