admin管理员组

文章数量:1391991

I recently added some url re-writing to my web application and had to added Page.Resolve URL to all my script images etc references. Now inside of those scripts, i have some ajax calls that now is not finding my webservices anymore. the Request URL is wrong i see looking at the error message. Is there anyway I can get to my webservices? thanks for any help.

What I had orginally thats not working now

$.ajax({
                type: "POST",
                url: "../MainService.asmx/UpdateInformation",
                contentType: "application/json; charset=utf-8",
                data: parameter,
                dataType: "json",

I recently added some url re-writing to my web application and had to added Page.Resolve URL to all my script images etc references. Now inside of those scripts, i have some ajax calls that now is not finding my webservices anymore. the Request URL is wrong i see looking at the error message. Is there anyway I can get to my webservices? thanks for any help.

What I had orginally thats not working now

$.ajax({
                type: "POST",
                url: "../MainService.asmx/UpdateInformation",
                contentType: "application/json; charset=utf-8",
                data: parameter,
                dataType: "json",
Share Improve this question asked Mar 20, 2012 at 14:03 user516883user516883 9,42823 gold badges76 silver badges115 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 5

Use this instead:

url: '<%=ResolveClientUrl("~/MainService.asmx/UpdateInformation")%>',

This will resolve the correct URL independently of the path the user is on. Note the ~. This means that the path will start at the root of the website.

Try and replace the url parameter with:

url: "/MainService.asmx/UpdateInformation",

or

url: "MainService.asmx/UpdateInformation",

Could always add something like this

<script type="text/javascript">
<% var siteroot = Url.Content("~/") %>

$.ajax({
            type: "POST",
            url: siteroot  + "MainService.asmx/UpdateInformation",
            contentType: "application/json; charset=utf-8",
            data: parameter,
            dataType: "json",

</script>

本文标签: cURL for ajax not working properly in aspnetStack Overflow