这个是我正在运营的网站接口,大家可以免费使用。有什么问题请给我留言评论或者发私信。
// JavaScript Document
//demo
//xhrrequest_opendata(1,'{"cip":"218.18.145.48","cid":"440307","cname":"广东省深圳市龙岗区"}',null);
//sessionStorage.getItem('transportbuf')=="http://hfx.link/3i71"
/*******************************************************
* @request_code 请求码
* @request_data 请求数据
* @return 去sessionStorage.getItem('transportbuf')里取
*/
function xhrrequest_opendata(request_code,request_data,fn)
{
var xhr=new XMLHttpRequest();
var url='http://1vg5062570.51mypc.cn/Vscode Projects/redbit/php/opendata.php/?timestamp='+Date.parse(new Date());
xhr.open("POST",url,true);
xhr.setRequestHeader("Content-Type", "application/json;charset=utf-8");
xhr.onreadystatechange=function()
{
if(xhr.readyState==4&& xhr.status==200)
{
if(xhr.response!=''&&xhr.response!=null)
{
try
{
sessionStorage.setItem('transportbuf',xhr.response);
if(fn!==null && typeof fn == 'function')
{
fn();
}
}
catch(err)
{
console.log(xhr.response);
//console.log(xhr.responseType);
//console.log(xhr.responseText);
console.log(err);
throw err;
}
}
}
}
try
{
var obj=new Object();
obj.request_code=request_code;
obj.request_data=request_data;
xhr.send(JSON.stringify(obj));
} catch (error) {
console.log(url);
console.log(obj);
console.log(xhr);
throw error;
}
}
|