PhoneGap JSONP SyntaxError:解析错误

时间:2013-06-04 13:03:22

标签: android cordova phonegap-plugins

使用cordova-2.0.0 + jquery-1.10.1

尝试在我的wordpress博客上获得授权

提出此请求

        $.ajax({
        url: "http://mydomain.ru/?json=auth.generate_auth_cookie",
        dataType: "jsonp",
        jsonpCallback: "myCallback",
        success: function (data) {
            alert('success');
        },
        error: function (data) {
            alert('error');
        }
    });

在我的localhost上,此请求已成功

myCallback({"status":"error","error":"You must include a 'username' var in your request."})

但是当我在Android模拟器或Android设备中尝试发出请求时,我收到错误

CordovaLog
SyntaxError: Parse error

Web Console
SyntaxError: Parse error at http://mydomain.ru/?json=auth.generate_auth_cookie&callback=myCallback&_=1370343811075:1

权限

<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.WRITE_CONTACTS" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> 
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.BROADCAST_STICKY" />

<access origin="http://mydomain.ru" subdomains="true" />

1 个答案:

答案 0 :(得分:2)

尝试以下代码

 $.ajax({type : "POST",
                data : {country_key:key},//this is specify the prameters
                url : urlname,
                dataType : 'json',
                success : function(jd) {    
                        alert('success');
                },
                error : function(jd) {
                    alert('fail');
                }
            });