[英]Why Unable to get success callback in Jquery/ajax call to RESTful services?
function GET() {
jQuery.support.cors = true;
$.ajax({
url: 'http://localhost:32253/api/UserDetail/GetRoleDetails',
type: 'GET',
async:true,
contentType: "application/json",
dataType: 'json',
xhrFields: {
withCredentials: true
},
error: function (xhr, status)
{
alert(status);
},
success: function (data) {
alert("Success!");
}
});
return false;
}
I am very much new to ajax,I tried a ajax call to my services method which returns value.But the success callback function is never fired .I only get error.What might be the reason? 我对ajax非常陌生,我尝试了ajax调用返回值的service方法。但是成功回调函数从未触发。我仅收到错误。可能是什么原因? I tried using dataType to jsonp and other similar solutions which had been found in Stackoverflow regarding this issue.Nothing worked out.I am getting server response as 200 oK.
我尝试将dataType用于jsonp和其他在Stackoverflow中发现的与此问题相关的类似解决方案,但没有解决,我收到200 oK的服务器响应。
try this code 试试这个代码
$.ajax({
type: "POST",
url: URL,
async: true,
contentType: "application/json; charset=utf-8",
dataType: "json",
jsonp: "onJSONPLoad",
jsonpCallback: "newarticlescallback",
crossDomain: "false",
beforeSend: function (xhr) {
},
error: function (request, status, error) {
console.log("Error In Web Service...." + request.responseText);
return false;
},
success: ajax_success,
complete: function (xhr, status) {
}
});
create function "ajax_success" in ur page like below 在您的页面中创建函数“ ajax_success”,如下所示
function ajax_success(parsedJSON) { //you code here
}
this may be help you try this code 这可能会帮助您尝试此代码
$.ajax({
type: "POST",
url: URL,
async: false,
contentType: "application/json; charset=utf-8",
dataType: "json",
jsonp: "onJSONPLoad",
jsonpCallback: "newarticlescallback",
crossDomain: "false",
beforeSend: function (xhr) {
},
error: function (request, status, error) {
console.log("Error In Web Service...." + request.responseText);
return false;
},
success: function (data) {
Result = data;
},
complete: function (xhr, status) {
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.