从JQuery调用ASP.NET Web Service

时间:2013-06-17 10:09:00

标签: jquery html json web-services rest

我是JQuery的新手,我想简单地创建一个用于调用ASP.NET Web服务的JQuery客户端。

这是我的HTML网页(里面有JQuery):

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Jquery WS call</title>
    <script language="javascript" type="text/javascript" 
        src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js">      
    </script>
    <script type="text/javascript">
        $(document).ready(function() {
            $("#btnCallWebService").click(function (event) {
                var webMethod = "http://wsIP/applications/time2gate.aspx";
                var x_loc = $('myForm.x_location').val();
                var y_loc = $('myForm.y_location').val();
                            var map_id = $('myForm.map_id').val();
                var dest_Gate = $('myForm.dest_gate').val();
                    var parameters = "{'x':'" + x_loc + 
                        "','y':'" + y_loc + 
                                            "', 'map':'" + map_id +
                        "', 'gate':'" + dest_Gate + 
                        "','mode':'routing" 
                        + "'session_id':'" + session_id + "'}";

                $.ajax({
                    type: "POST",
                    url: webMethod,
                    data: parameters,
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    success: function(msg) {    
                        alert("Service response: " + msg);
                    },
                    error: function(e){
                            $(divToBeWorkedOn).html("Unavailable");              
                    }
                    });
            });
        });
    </script>
</head>
<body>
    <form id="myForm">
    X:<input id="x_location" type="text" /><br />
    Y:<input id="y_location" type="text" /><br />
    Map: <input id="map_id" type="text" /><br />
    Gate:<input id="dest_gate" type="text" />
    <input id="btnCallWebService" value="Call WS" type="button" />
    </form>
    <div id="response" />
</body>
</html>

问题在于,每当我拨打电话时,我都没有得到任何回应。我在Mozilla Firefox v21.0浏览器上测试它。 WS端点如下:

http://wsIP/applications/time2gate.aspx?x={x-val}&y={y-val}&map={map-id}&gate={destination-gate}&mode=routing

我做错了什么?

谢谢, 尼克

0 个答案:

没有答案