Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

phonegap, android only: Uncaught Error: Unexpected Content: null #66

Closed
lorenzosfarra opened this issue Nov 17, 2014 · 7 comments
Closed

Comments

@lorenzosfarra
Copy link

Hello!
Here's the problem...
The same code works if I run this on the iOS simulator, but on Android I have the following error:

11-17 18:22:27.318: D/CordovaLog(1778): file:///android_asset/www/js/jquery.soap.js: Line 392 : Uncaught Error: Unexpected Content: null

The code is very easy, as I'm only testing some features.
So the code to include js files is the following:

<script type="text/javascript" src="cordova.js"></script> <script type="text/javascript" src="js/jquery.js"></script> <script type="text/javascript" src="js/jquery.soap.js"></script> <script type="text/javascript" src="js/index.js"></script> <script type="text/javascript"> app.initialize(); </script>

in app.initialize I wait for the "deviceready" event to fire the following jquery soap call:

$.soap({
             url: 'http://<soapurl_here>/api/?wsdl',
             method: 'login',
             data: {
               username:'<user_here>',
               apiKey:'<api_key_here>'
             },

             success: function (s) {
               alert("success");
             },
             error: function (e) {
               alert("error");
             }

             });

Any hints?

Thanks in advance!

@doedje
Copy link
Owner

doedje commented Nov 18, 2014

When you use:

file:///android_asset/www/js/jquery.soap.js

and

http://<soapurl_here>/api/?wsdl

You will indeed get a

Uncaught Error: Unexpected Content: null

Due to same-origin policy... Try not to use file:// but only http:// for your test-setup. Based on the info you provided my guess is there is your problem, good luck!

@lorenzosfarra
Copy link
Author

Hi, first of all thanks for your reply.
It's quite strange because the same-origin policy is "solved" by phonegap using the concept of whitelist. I am using the <access origin="*" /> setting, both for android and iOS (and on iOS works), and the code is equivalent. This is why I am completely stuck, asking for your hints.

[UPDATE] And it seems that:

Luckily since your PhoneGap application is running off of the file:// protocol it isn't limited by the same origin policy. This means we can request data using XmlHttpRequest from any domain.

as stated in different documents like this blog post

Thanks!

@doedje
Copy link
Owner

doedje commented Nov 18, 2014

Well in that case I suspect The problem to be with phonegap, The error is clearly pointing in the direction of same origin policy problems...

@lorenzosfarra
Copy link
Author

Yep, at this point I agree...totally something not related to this library, thanks for your answers anyway.

@doedje
Copy link
Owner

doedje commented Nov 18, 2014

Unfortunately I have no experience with phonegap, so I won't be able to help you any further... When you do find some interesting information, please consider sharing it here, you might be helping other phonegap/jquery.soap programmers with your findings! =]

good luck!

@doedje doedje closed this as completed Nov 18, 2014
@Haibarbe-Kreativ
Copy link

Hi there,
I recently have done an phonegap iOS and Android App for an client of mine that is now in stores and uses jquery.soap to contact a SOA-Webservice.
It was a little bit of pain at first but then works out fine.
I will give you some code snippets of mine, maybe that helps.

var Network = {
soapRequestInit: function () {
    $.soap({
        url: 'http://www. [ yourURLHere ] .asmx',
        soap12: true,
        appendMethodToURL: false,
        namespaceQualifier: '[ yourNamespaceQualifier ]',
        namespaceURL: 'http://www. [ yourURLHere ] .asmx',
    });
},
logIn: function (password, name, saveit) {
$.soap({
        SOAPAction: 'http://www. [ yourURLHere ] .asmx/LogIn',
        method: 'LogIn',
        data: {
            userName: name,
            password: password
        },
        beforeSend: function (obj) {
            console.log("soap-env: " + obj.toString());
        },
        success: function (soapResponse) {
            //...do the relevant stuff
            //...

        },
        error: function (SOAPResponse) {
            console.log("Error: " + SOAPResponse.statusText);
            $.mobile.loading('hide');
            //...do the relevant stuff
            //...

        }
    });
},
//...other methods of the Network-Object 
//...

}

I did not have to whitelist anything, there where just a couple of headers that had to be set at the webservice for output.
These where the following:
Access-Control-Allow-Origin: *
Access-Control-Allow-Headers : SOAPAction und/oder Content-Type

If these headers are set on the response it should work fine.

@lorenzosfarra
Copy link
Author

Thanks for the reply! I will take inspiration from the above code to try something in the one I have, thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants