在Android模拟器上混淆jQuery / jsonp失败

时间:2013-01-11 12:23:40

标签: android jquery jquery-mobile android-emulator

我正在尝试使用andriod模拟器上的jsonp调用服务:

    bindEvents: function() {
        document.addEventListener('deviceready', this.onDeviceReady, false);
    },

    onDeviceReady: function() {
        app.receivedEvent('deviceready');
    },

    receivedEvent: function(id) {
        console.log('Received Event: ' + id);

        $.ajaxSetup ({  
            cache: false  
        });

        $.ajax({
            type: "GET",
            url: "http://10.0.2.2/uk-en/login/user",
            dataType: "jsonp",
            contentType: "application/json",
            success: function(xml){
                $("#result").html('123');
            },
            error: function(XMLHttpRequest, textStatus, errorThrown) { 
                $("#result").html('XMLHttpRequest = ' + JSON.stringify(XMLHttpRequest) + ", textStatus = " + textStatus + ', errorThrown = ' + JSON.stringify(errorThrown));
            } 
        });
    }

我在HelloWorld应用程序上执行此操作,在phonegap站点上创建以下文档。我的index.html与此类似:

<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <meta name="format-detection" content="telephone=no" />
    <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" />
    <link rel="stylesheet" type="text/css" href="css/index.css" />

    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
    <title>Hello World</title>
</head>
<body>
    <div class="app">
        <div id="result">

        </div>
    </div>
    <script type="text/javascript" src="cordova-2.2.0.js"></script>
    <script type="text/javascript" src="js/index.js"></script>
    <script type="text/javascript">
        app.initialize();
    </script>
</body>

这是我收到的错误,虽然这可以在我的本地计算机上使用Firefox:

XMLHttpRequest = {"READYSTATE":4,"STATUSTEXT":"SUCCESS"},TEXTSTATUS = PARSERERROR, ERRORTHROWN = {"MESSAGE":JQUERY1830456564654_32131 WAS NOT CALLED", "STACK":"ERROR:JQUERY1830456564654_32131 WAS NOT CALLED"\N AT FUNCTION.ERROR(http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js:2:13215)

有人能帮忙吗?

1 个答案:

答案 0 :(得分:0)

JSONP要求将回复包含在某种回调函数中。

这是假设您正在抓取其他域中的内容。如果是这样,那么您受到origin policy:

的限制

所以服务器应该回复:

urFunction({....});