Problem with passing folder path string to web service function via jQuery.ajax

Posted by the_V on Stack Overflow See other posts from Stack Overflow or by the_V
Published on 2010-04-24T16:55:41Z Indexed on 2010/04/24 17:03 UTC
Read the original article Hit count: 156

Filed under:
|
|
|

Hello,

I need to perform asp.net web-service function call via jQuery and pass asp.net application path to it. That's the way I'm trying to do it (code is located within asp.net page, e.g. aspx file):

    var d = "{'str':'<%=System.DateTime.Now.ToString() %>', 'applicationPath':'<%=GetApplicationPath() %>'}";

    $.ajax({ type: "POST",
        url: "http://localhost/testwebsite/TestWebService.asmx/Test",
        data: d,
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        error: function (xhr, status, error) {
            var err = eval("(" + xhr.responseText + ")");
            alert(err.Message);
        },
        success: function (msg) {

        }
    });

That's what GetApplicationPath method looks like:

protected string GetApplicationPath() 
{
    return HttpUtility.HtmlEncode(Request.PhysicalApplicationPath);
}

And here is a header of web-service function which I'm trying to call:

public void Test(string str, string applicationPath) 

Function call works well, but applicationPath parameter doesn't passed correctly. When I debug it I see that backslashes are removed, function gets "C:ProjectsSamplesmytestwebsite" instead of "'C:\Projects\Samples\mytestwebsite\'".

How can I overcome this?

© Stack Overflow or respective owner

Related posts about .NET

Related posts about jQuery