开发者

Calling asmx via jquery gets wrong url

For a few days now I have been trying to 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: "开发者_C百科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 it's worse, because if I'm on a page admin/products/edit then the ajax goes to admin/products/edit/webservice.asmx which is definitely 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 can't test anything this way.


This will resolve the right url server side:

<%=ResolveUrl("~/WebService.asmx/HelloWorld")%>
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜