views:

22

answers:

1

hi everyone

4 a few days now im trying 2 get an asmx webservice to work via jquery

Heres my code

<script type="text/javascript">
    $(document).ready(function () {
        $("#btnTest").click(function () {
            $.ajax({
                type: "POST",
                url: "/WebService.asmx/HelloWorld",
                cache: false,
                contentType: "application/json; charset=utf-8",
                data: "{}",
                dataType: "json",
                success: function (data) {
                    alert(data);
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) { alert(textStatus + ' ' + errorThrown + ' ' + XMLHttpRequest); }
            });
        });
    });
</script>

The problem seems to be that the browser checks for this url:

http://localhost:52657/WebService.asmx/CheckSmtp

when it should really check for this url

http://localhost:52657/myappname/WebService.asmx/CheckSmtp

so I tried without the slash in the $.ajax url, but then its worse, because if im on a page admin/products/edit then the ajax goes to admin/products/edit/webservice.asmx which is definetly wrong

so how do I tell jquery to look in the root folder?

It may be that the problem is only on localhost, but I cant test anything this way

Thanks a million

A: 

This will resolve the right url server side:

<%=ResolveUrl("~/WebService.asmx/HelloWorld")%>
Mattias Jakobsson
thanks a million. actually meanwhlile someone sent me a tip of putting a label in the master page that gets its value server side to the root path. and it worked. but this technique fixed me a different problem . the src of the javascript wasnt either resolving correctly. i used ur answer and it works. thanks. amchoo?
Yisman