2

I am trying to make a JSONP call in my PhoneGap application. It works fine in my desktop browser, but not in the device. I thought it might be an issue with the jQuery Mobile, so I even tried disabling it, but doesn't help.

Android version: 3.0

This is my code:

<link rel="stylesheet"  href="css/themes/default/jquery.mobile-1.1.0.css" />
<script src="js/jquery.js"></script>
<script src="js/jquery.mobile-1.1.0.js"></script>
<script src="cordova-2.1.0.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
    function cancelclicked() {
        window.location.href="index.html";
    }

     function jsonp_call()
        {
            // The call request here
        }
        function parseRequest(response)
        {
            // Parse the response here
        }
</script>

<div data-role="page" class="type-interior">

<div data-role="header" data-theme="b">
    <h1>Login</h1>
</div>
<div data-role="content">
    <div class="content-primary">
            <div data-role="fieldcontain">
             <label for="name">Username:</label>
             <input type="text" id="uname" />
            </div>

            <div data-role="fieldcontain">
             <label for="name">Password:</label>
             <input type="password" name="name" id="pass"  />
            </div>
            <div data-role="fieldcontain">
                <label for="name" id="invalidlogin"></label>
            </div>
            <div class="ui-body ui-body-b">
            <fieldset class="ui-grid-a">
                    <button type="submit" onclick="return jsonp_call()" data-theme="e" rel="external">Login</button>
                    <!--</form>-->
                    <button type="submit" onclick="cancelclicked()" data-theme="d">Cancel</button>
            </fieldset>
            </div>
    </div>
</div>

What am I missing here? It works fine on a browser, so I'm quite sure that the JSONP code is correct. It fails on the emulator and the device as well.

4

2 回答 2

2

Did you add the domain name into the Cordova config file? It is under res/xml/config.xml

<access origin="bla.bla.domain.com" />
于 2013-02-02T20:03:51.360 回答
1

For me the access origin setting was already set. But still i got the problem.

It turns out to be a couple of missing closing HTML tags. (in my case closing A HREF tags ) When i only changed this, it was working again on Android. Chome automatically fixed the missing closing tags.

Quite a headache, because i had no problems during testing in my webbrowser, and i thought it had to do with the jsonp implementation, or security/signing issues.

于 2015-03-22T18:49:48.460 回答