我在服务器端创建了[WebMethod]
,如下所示:
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Xml)]
public string ReadComments(string pagenum)
{
return pagenum;
}
和ajax代码:
function GetCommentItems() {
var pageTrack = $("input[id$='pageTrack']").val();
$.ajax({
url: "/_layouts/15/Load5MoreComments/CommentFetchSvc.asmx",
type: "POST",
dataType: "xml",
beforeSend: function (xhr) { xhr.setRequestHeader('SOAPAction', 'http://tempuri.org/ReadComments'); },
data: '<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><ReadComments xmlns="http://tempuri.org"><pagenum>testStr</pagenum></ReadComments></soap:Body></soap:Envelope>',
contentType: 'text/xml; charset=utf-8',
success: function (msg) {
console.log(msg);
var newPageTrack = $("input[id$='pageTrack']").val();
$("input[id$='pageTrack']").val(parseInt(newPageTrack) + 1);
},
error: function (xhr, msg) {
console.log(msg + '\n' + xhr.responseText);
}
});
}
我传递testStr
作为参数,但它始终为null。
我试过这个processData: false,
但没有用
请帮帮我!