我有以下函数,它假设要与另一个服务器对话,检索json数据并显示它,问题是该函数甚至没有发起查询我做错了什么?代码被上传到apache tomcat服务器,我使用wireshark进行跟踪,在http端口上没有。
$(document).ready( function() {
var home_add='http://wcf.net:3300/gateway';
$('#handshake').click(function(){
alert(" sending json data");
function handshake(){ /*testing the function */
var data_send = {
"supportedConnectionTypes": "long-polling",
"channel": "/meta/handshake",
"version": "1:0"
};
$.ajax({ /* start ajax function to send data */
url:home_add,
type:'POST',
datatype:'json',
contanttype:'text/json',
async: false,
error:function(){ alert("handshake didn't go through")}, /* call disconnect function */
data:JSON.stringify(data_send),
success:function(data){
$("p").append(data+"<br/>");
alert("successful handshake")
}
})
}
})})提前感谢您的反馈意见
发布于 2010-12-21 01:14:56
你不调用握手函数...
$(document).ready(function () {
var home_add = 'http://wcf.net:3300/gateway';
$('#handshake').click(function () {
alert(" sending json data");
$.ajax({ /* start ajax function to send data */
url: home_add,
type: 'POST',
datatype: 'json',
contanttype: 'text/json',
async: false,
error: function () { alert("handshake didn't go through") }, /* call disconnect function */
data: {
"supportedConnectionTypes": "long-polling",
"channel": "/meta/handshake",
"version": "1:0"
},
success: function (data) {
$("p").append(data + "<br/>");
alert("successful handshake")
}
});
});});
发布于 2012-12-24 13:05:51
如果您正在使用Internet Explorer,则需要在您jsp页面的head部分中添加以下代码
<script src="https://github.com/douglascrockford/JSON-js/blob/master/json2.js" />试试这个,然后检查一下,也许它会起作用。
https://stackoverflow.com/questions/4491978
复制相似问题