我创建web方法并创建一个调用此Web方法的Ajax请求我有内部服务器错误但是当我从URL直接调用webservice时工作正常我的ajax请求:
$(document).ready(function () {
$('#btnsave').click(function () {
var x = 'sss';
$.ajax({
url: "/WS/WS.asmx/AddCustomer",
type: 'GET',
dataType: 'json',
data: { CustomerType: x },
contentType: 'application/json; charset=utf-8',
error: function (XMLHttpRequest, textStatus, errorThrown){
alert("Request: " + XMLHttpRequest.toString() + "\n\nStatus: " + textStatus + "\n\nError: " + errorThrown);
},
success: function (response) {
if (response.d) {
}
}
});
});
});`
答案 0 :(得分:0)
试试这个,看看(数据:“{CustomerType:'”+ x +“'}”,)......
$(document).ready(function () {
$('#btnsave').click(function () {
var x = 'sss';
$.ajax({
url: "/WS/WS.asmx/AddCustomer",
type: 'GET',
dataType: 'json',
data: "{CustomerType:'" + x+ "'}",
contentType: 'application/json; charset=utf-8',
error: function (XMLHttpRequest, textStatus, errorThrown) {
alert("Request: " + XMLHttpRequest.toString() + "\n\nStatus: " + textStatus + "\n\nError: " + errorThrown);
},
success: function (response) {
if (response.d) {
}
}
});
});
});
答案 1 :(得分:0)
我有同样的错误,请参阅下面的代码,它对我有用,但如果它不起作用,请更改类型:'POST'。
$.ajax({
url: 'your URL',
type: 'GET',
contentType: "application/json; charset=utf-8",
datatype: 'JSON'
}).fail(function (jqXHR, textStatus, errorThrown) {
alert(textStatus + " : " + errorThrown);
}).done(function (JSData) {
for (var i = 0; i < JSData.length; i++){
//your code
}
});