0

I am trying to set up a simple set up as follows: Have a mobile app with a page consisting of 4 lines (4 html paragraph lines (I am using phonegap)).

I want to use a web page from which I will input the data for those 4 lines. This information is sent to a server and that server transfers this information to that app on that mobile phone. Now, those 4 lines on the mobile phone is filled with the new information.

Similarly user inputs information on another page consisting of 10 lines of li (list). This information is again sent to the server and to the web page where the information is displayed.

I can almost feel the "internet police guys" getting all hyped and ready to vote this question down. But please understand that I have been on this site and various forums desperate to find a tutorial to guide me to do this and not able to find.

I am trying to use ajax to perform this setup. Confused how I would be using the php file. Information such as password n username is going to go in that php file to connect to the server. But php is a server side script thus needs to sit at the public_html folder. How do I use the php file from my desktop? Write a separate javascript to access it?

It is the concept that is confusing me. I am familiar with html,js,php.

I would appreciate any guidance or maybe a link to a tutorial which would help me to do the concept I mentioned. Thanks for listening.

user3439075
  • 59
  • 1
  • 9
  • Hmm I am guessing I was wrong to assume this is not a complicated question from the response. – user3439075 Mar 19 '14 at 19:08
  • The reason you're not getting a response is that the question is so broad. StackOverflow isn't really a tutorial site; it's a place to ask specific questions that can be answered with (relatively small) bits of specific code. The question you posted is more or less, "How do I build a web service, and a mobile app, and then make that mobile app communicate with that web service?". So, look for tutorials about all those things first, then try some things out, and when you get stuck on *specific* parts, come back here and ask for help. You'll have much better luck that way! – sgress454 Mar 19 '14 at 19:19

2 Answers2

0

You will need to create an API using PHP. This API is uploaded to your server and is considered "RESTful". Google a tutorial for what fits your needs. You can set all sorts of rules in this API such as requiring any requests to have an ID or access token.

Since you are using PhoneGap, your HTML and JS files rest on the device, so you will need to allow permissions to your API from anywhere. For this you will have to speak to your host provider about unless you know how to configure it yourself (some providers restrict what you want to do by default as an extra security precaution against XSS attacks).

Next, you can either use jQuery, or you can write some AJAX calls by writing the JavaScript yourself.

The most efficient way for this to work is to send JSON objects to and from the API. You will include a "command" in the JSON when you are sending from your app. On the PHP side, you will retrieve this command and use the rest of the data included in your JSON object to process the request. Your API will need to encode a JSON object for return (such as a user's profile information).

Here is a basic PHP API tutorial to get you going that explains some of the features of a RESTful API: PHP API

Here is a simple AJAX function (you will probably want to make this much more modular): AJAX

Community
  • 1
  • 1
KevBot
  • 14,556
  • 3
  • 37
  • 59
0

As broad as your question is, it seems like the best/easiest thing for you to do will be for you to first create a PHP webpage that will access a SQL database to perform the record updating. Actually, this should serve all of your needs for your mobile users assuming you don't need push notifications for live data updates.

I am assuming, since you are using phone gap, that you are more comfortable with web languages. After you get the webpage fully operational, then you should start building your app based on that exact same SQL database. With mobile app development there are a lot more "what if's" (what if the phone rings, what if the app is running in the background, what if there is no cellular service, etc...)

It is always easier to start with what you know and build on that, rather than starting with a new development platform and troubleshooting as problems arise.

NathanC
  • 38
  • 8