簡體   English   中英

從jQuery 1.9.2調用Web服務

[英]Calling Web Service from jQuery 1.9.2

我只是想從jQuery調用Web服務。 我的代碼是

function SearchCandidates() {
$("#txtSearchGlobal").autocomplete({
    source: function (request, response) {
        $.ajax({
            type: "POST",
            url: "WebService.asmx/HelloWorld",
            contentType: "application/json; charset=utf-8",
            data: "{}",
            dataType: "json",
            success: function (data) {                    

            },
            error: function (req, status, error) {
                alert("ERROR:" + error.toString() + " " + status + " " + req);
            }
        });
    },
    minLength: 2,
    select: function (event, ui) {

    }
});

}

此處,出現錯誤消息"ERROR : Internal Server Error error [object object]" ,無法找到確切的錯誤。 我已經使用了上面提到的相同的代碼,已經很多次了,但是我沒有發現任何問題。 我在這里使用jQuery 1.9.2,我認為版本不是問題。 任何人都可以在這里幫助我,謝謝。

從您的代碼中刪除成功的else並檢查並還將數據類型設置為Jsonp以下代碼可能對您有幫助

$.ajax({
 type: "POST",
url: url,
data: data,
 dataType: 'jsonp'
success: function(data){
 alert(data)
},
error:function(req, status, error){
 alert(JSON.stringify(error))
}   
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM