WebWorks中使用JQuery的getJSON方法进行跨域访问

来源:互联网 发布:linux 一键安装lnmp 编辑:程序博客网 时间:2024/06/06 12:59

遇到的问题:

问题1. Firefox, Chrome都不能回调checkSIGNIN_callback方法

诊断: 在服务器用wireshark上监听89端口数据访问。发现有数据请求到达89端口,服务器正常返回JSON格式的数据给客户端

解决:使用RIM的Ripple进行调试,不使用Firefox, Chrom


问题2. 黑莓真机上面上测试,该code又出现不能访问服务器的问题

诊断:在服务器上监听89端口,发现根本没有数据请求到达,也没有数据返回。

问题的可能的症结:

  a)config.xml文件里面access controll 

  b)运营商(联通)网络对特殊端口89的访问限制

  c) 黑莓BES服务器不运行访问除80,8080端口外的TCP端口

解决方法:

a)服务器上做端口修改或者端口映射,最后把89端口改成了8080端口;同时程序中把端口89改为8080。



JQuery 代码片段:

注意要跨域访问,需要加一句

jQuery.support.cors = true;



function checkSIGNIN_callback(data) {
if (data.signInTime == "") {//not sign in$("#signin_button").text("签到");  $('#signin_button').button('refresh');}if (data.signOutTime == "") {//not sign out$("#signin_button").text("签出");  $('#signin_button').button('refresh');}else {$("#signin_button").text("签到/签出");  $('#signin_button').button('refresh');}alert(6);}function checkSIGNIN() {alert("gPhone is " + gPhone);jQuery.support.cors = true;checkSIGNIN_url = "http://shanghai.springworks.info:89/pgps/empPr/empParamAction_sendEmpParam.action?phone=" + gPhone;$.getJSON(checkSIGNIN_url, checkSIGNIN_callback);}


原创粉丝点击