Problem with passing folder path string to web service function via jQuery.ajax
- by the_V
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?