The greatest WordPress.com site in all the land!

  1. The url shud be something similar to http://ipAddress or domainName/ajaxDemo/json/sample.json?callback=jsonCallback
  2. the ipAddress should the be ip of the system, if its localhost or 127.0.0.1 or 192.x.x.x the call would fail.
  3. The response json shud be wrapped with a callback method name I.e jsonCallback in our case
     jsonCallback({
     "sampleFlag1" : "This is sample value 1",
     "sampleData2" : "This is sample val 2",
     "sessionKey": "This is a key"
     });
     
  4. Datatype shud be “jsonp”
    $.ajax({
    type: 'GET',
    url: 'http://ipAddress or domain name/ajaxDemo/json/sample.json?callback=jsonCallback',
    data: {},
    dataType:'jsonp',
    contentType: 'application/json',
    cache:false,
    jsonpCallback: 'jsonCallback',
    crossDomain : true,
    success: function(originalResponse, status, request){
    $("#respCntr").html(originalResponse.sessionKey);
    },
    error: function(XMLHttpRequest, textStatus, errorThrown) {
    $("#respCntr").html("error");
    }
    });
    
  5. Add an entry in  res/config.xml <access origin=”http://ipAddress or Domain name” subdomains=”true”/>
About these ads

Comments on: "How to make Ajax request in PhoneGap using JQuery" (1)

  1. Iˇ¦ll right away take hold of your rss as I can not to find your email subscription hyperlink or newsletter service. Do you have any? Kindly permit me realize in order that I may just subscribe. Thanks.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: