开发者

AJAX call to a WebMethod

I have the following Webmethod in my C#/.NET web-application, file lite_host.aspx.cs:

[WebMethod]
public static bool UpdatePage(string accessCode, string newURL)
{
    bool result = true;
    try {
       HttpContext.Current.Cache[accessCode] = newURL;
    }
    catch {
        result = false;
    }

    return result;
}

It should get the values of "accessCode" and "newURL" from a JavaScript function via a jQuery AJAX call with and make the appropriate changes in Cache:

function sendUpdate() {
       var code = jsGetQueryString("code"); 
       var url = $("#url_field").val();
       var options = { error: function(msg) { alert(msg.d); },
                       type: "POST", url: "lite_host.aspx/UpdatePage",
                       data: {'accessCode': code, 'newURL': url}, 
                       contentType: "application/json; charset=utf-8",
                       dataType: "json",
                       async: false, 
                       success: function(response) { var results = response.d; } }; 
       $.ajax(options);
}

However whe开发者_运维技巧n I call the sendUpdate() function, I my script ends on $.ajax error and I'm getting an alert text "undefined".


Undefined means that msg.d doesn't exist. Try doing a console.log(msg) and use Chrome's debugger to see what is outputted (yeah, I know) to the console.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜