qinpengyue

ajax 请求jsonp的数据

1.当使用json存在跨域在资源共享问题:需要用jsonp  

jQuery.ajax({
url: \'http://www.e-zhuan.com/。。。?。。。,
dataType: \'jsonp\',
jsonpCallback:"datas",
type: \'get\',
async:false,
success: function(data) {
if(data.yiwan < data.cishu){
alertMsg("。。。。。");

} else {
alertMsg("。。。。。");
}
}

});

 

2.

公用方法

function myAjax (_data, _url, callBack) { 
jQuery.ajax({
type: "post",
url: _url,
data: _data,
cache: false,
datatype: "json",
success: function (data) {
if (callBack != undefined) {
callBack(data);
}
},
error: function (XMLHttpRequest, textStatus, errorThrown) {

}
});
}

//获取请求地址所传的name参数值
function GetQueryString(name)
{
var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
var r = window.location.search.substr(1).match(reg);
if(r!=null)return unescape(r[2]); return null;
}

//调用方法

var url="http://www.e-zhuan.com/game/getGamepart";
myAjax({zkg:GetQueryString("zkg"), fwxxs:a, gzchd:18, gckpe:"xiaoxingxing" }, url,function(data){

});

 

发表于 2016-02-25 11:35  求学之路已存在  阅读(281)  评论(0编辑  收藏  举报
 

分类:

技术点:

相关文章:

  • 2022-12-23
  • 2021-05-27
  • 2021-06-07
  • 2021-12-25
  • 2022-12-23
  • 2022-12-23
  • 2021-06-08
猜你喜欢
  • 2021-07-17
  • 2021-11-26
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-22
相关资源
相似解决方案