0

I am working on project and I will implement by HTML5, javascript and I will use phonegap to give me applications in multi platforms and I have database in my server.

I know two ways to connect to my database and phoneGap accept that way :

1:Jquery Ajax requests. like in the tutorial http://www.indiageeks.in/phonegap-jquery-ajax-example-jsonjavascript-object-notation-response/

2:java script like in the tutorial http://simonmacdonald.blogspot.com/2011/12/on-third-day-of-phonegapping-getting.html

but I am wondering ,,, Can I use web services on this thing ? for example : all services will be in my server and also the database and I will connect to the web services through (html or java script or Jquery ) page and the data return in XML file and display it in the page.

Does phoneGap accept that way ? if yes i want any good tutorials that will help me

Mesho
  • 53
  • 1
  • 8

2 Answers2

0

It is a little difficult to be specific without knowing your server technology...

You can GET/POST to URLs from javascript, so yes you can access a webservice.

I have typically used MVC WebAPI projects to allow my phonegap applications to interact with the server.

WCF webservices work as well. This is a good example: http://www.codeproject.com/Articles/132809/Calling-WCF-Services-using-jQuery

You would access them in exactly the same way as you would from a normal web application, with a couple of gotchas:

You need to allow the origin within the res/xml/config.xml file, to test you can allow all origins: <access origin="*" /> Add this tag under the widget tag.

You must enable CORS on the web server.

I would expose/consume JSON from the webservice, this is a natural serialization format for javascript based applications, with built in serialize/deserialize functions.

You can also download the output of the webservice to a file on the device using:

Download files and store them locally with Phonegap/jQuery Mobile Android and iOS Apps

Community
  • 1
  • 1
Marcus
  • 97
  • 1
  • 2
  • 8
0

You can use below method for making JSON request

var apiurl = "your url";

   $.ajax({
      url : apiurl,
      dataType : 'jsonp',
      data : {
         token : Token,
         key : keyuser,
         method : 'method_name'
      },
      success : function(data) {
               // here all output come and do action 
        console.log("data is " + data);

      },
      failure : function() {
         console.log("error");
      }
   });
Amarjit
  • 4,327
  • 2
  • 34
  • 51