格式化AJAX的URL

时间:2014-07-09 15:19:02

标签: jquery ajax asp.net-mvc asp.net-mvc-4

我有一个通过AJAX调用Web服务的jQuery程序。请参阅我之前提到的question中的代码:

<script type='text/javascript'>
    $(document).ready(function () {
        $("button").click(function(){
            alert('Test');
            $('#div1 h2').text('Hi I am replace');
            var divToBeWorkedOn = "#div1";
            var n1 = 1;
            var n2 = 2;
            var webMethod = "Service1.svc/getNumber";

            $.ajax({
                type: "POST",
                url: webMethod,
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (result) {
                    $(divToBeWorkedOn).html(val(result));
                },
                error: function (e) {
                    $(divToBeWorkedOn).html(e.responseText);
                }
            });
        })
    });
</script>

我在阅读以下question之后发现,您无法使用jQuery进行跨域调用而不应用我现在已经完成的设置。

如何指定AJAX URL。以下两个错误:

http://mypc/Service1.svc/HelloWorld
http://mypc/Service1.svc\HelloWorld

HelloWorld是我要调用的功能,包含在Web服务中。 HelloWorld会返回integer

0 个答案:

没有答案
相关问题