$ .Ajax in jQM mobile app with phone not working on iOS devices

I have a login button for a jQuery Mobile app. When the login button is clicked, the soap call is invoked using the $ .ajax () method. This works on browser and Android phones, but the control doesn't even go into $ .ajax () on iOS devices. Here is my sample code.

var User = $("#txtUsername").val();
var Psw = $("#txtPwd").val();
var soapMessage = '<?xml version="1.0" encoding="utf-8"?>'
                    + '<SOAP-ENV:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Body><ns0:UserLogin SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns0="urn:LoginSrvcVi"><userId xsi:type="xsd:string">'+User+'</userId><password xsi:type="xsd:string">'+Psw+'</password></ns0:UserLogin></SOAP-ENV:Body></SOAP-ENV:Envelope>';

$.ajax({
        url : myLoginUrl,
        type : "POST",
        username : User,
        password : Psw,
        dataType : "xml",
        data : soapMessage,
        contentType : "text/xml; charset=\"utf-8\"",

        success : function(data, textStatus, jqXHR) {
            debugger;
            $.mobile.loading('hide');
            console.log("data" + data);
            var x2js = new X2JS();
            var test = x2js.xml2json(data);                                                     
            debugger;
            if (test.Envelope.Body.searchUserLoginResponse.Response.messages.item != "Data Retrived Successfully") 
            {
                alert("Success");
            }
        },

        error : function(jqxhr) 
        {
            alert("Error");
        }

    });

      

Note. I tried the SOAP URL to run in safari, but it only shows a blank screen and no data. Chrome on android renders XML structure.

Help is needed. Thanks to

+3


source to share


2 answers


Try to wrap all your code inside the document.ready event callback like this:



$(document).ready(function () {
   // Your code here
});

      

+1


source


If your request works correctly on Android and Desktop browsers, but not on iOS, then it looks like there might be an error in the iOS app configuration for CORS. Given that you mentioned that async: false

you get an "unauthorized error" when you try to make a call with , it looks like your domain whitelisting configuration might be the source of this problem.

Make sure you add the domain to the whitelist configuration in the AppName / config.xml file (for iOS) and also in the res / xml / config.xml file (for Android). Be sure to check out the documentation for more information on how to add the correct configurations. As mentioned in this post , the config.xml file you need to change for iOS is the one in the project folder (AppName, in the example above) refers to the project folder).

As you will see in the documentation, there are many different configurations that you can use to whitelist your domains, and some are more secure (to be more specific) than others. The following configuration can be used to provide access to all domains, but is very non-specific and therefore less secure:



<access origin="*" />

      

Once you are sure that your iOS whitelist configuration is up to date, install async: false

and retry the request.

+1


source







All Articles