我是 JQuery 新手,我想简单地创建一个 JQuery 客户端来调用 ASP.NET Web 服务。
这是我的 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
我究竟做错了什么?
谢谢,尼克