AJAX:参数始终为null XML格式

时间:2017-10-10 07:52:54

标签: javascript c# jquery ajax visual-studio

我在服务器端创建了[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,但没有用 请帮帮我!

0 个答案:

没有答案