Push API v3能用jq的ajax去调用吗?如果可以,我的怎么报个跨域的错误?看代码

47838923
2016-12-27 06:38 1.2k 0

js 代码:

function jpushTest(){

var data={
 "platform": "all",//推送平台设置
 "audience":"all",//推送 设备
     "notification": {
        "android": {
            "alert": "Hi, JPush!",
            "title": "Send to Android",
            "builder_id": 1,
            "extras": {
                "newsid": 321
            }
        },
        "ios": {
            "alert": "Hi, JPush!",
            "sound": "default",
            "badge": "+1",
            "extras": {
                "newsid": 321
            }
        }
    },

};


    $.ajax({
     headers: {

     "Authorization":window.btoa("3b2434c5aafb6a1339ceee51:3a228be003ea9e1c6a54a2a5")
     },
        url:'https://api.jpush.cn/v3/push',
        type:'post',
       contentType: "application/json",
            dataType: 'json',
            data: JSON.stringify(data),
//        data:QueryCondition,
        success: function(data){
        alert("ok:"+$api.jsonToStr(data));
        },
        error:function(err){
        alert("err"+$api.jsonToStr(err));
        }

        });

}

报错:

First.html:1 XMLHttpRequest cannot load https://api.jpush.cn/v3/push/validate. 
Response to preflight request doesn't pass access control check: 
No 'Access-Control-Allow-Origin' header is present on the requested resource. 
Origin 'null' is therefore not allowed access.

1个回答

热门排序