Reputation: 2891
What format for the response should be?
XML or JSON??
Can it be parsed?
I have tried before using Java when developing my Android native apps
but now, I am trying to write apps using JQuery Mobile.
Upvotes: 0
Views: 197
Reputation: 68
Both XML and JSON can be used and parsed.
I recommend JSON!
For example:
If you have a XML document with many levels of nested nodes you might end up with multiple nested loops ($.each function from jQuery).
The advantage of JSON is that it's very easy to get the data you need since its already native javascript. You won't need parsers or proxies, just loop the data fast and simple.
XML is more human-readable but if you document your JSON responses, you won't have any problems with future modifications.
In PHP it's very easy to generate a JSON string from an array of data brought from the MySQL DB (use json_encode(<<insert array here>>)
function).
Have fun,
Bogdan
Upvotes: 1
Reputation: 38147
This is a very vague question .....
The data can be XML / JSON / HTML / whatever format you want .... you just need to deal with that format in Javascript to present to the user.
For example if you are using an ajax based table then the output might be JSON or XML. But if you are loading in a div or a section of a page - you might return HTML that has been though a VIEW layer in an MVC based application.
There are many methods for doing this - if you give specific examples or things you have tried it would make things a lot easier ....
Upvotes: 1
Reputation: 7371
Javascript has a native function JSON.parse() and JSON.stringify() which makes it very simple to send/receive data. PHP also has an equivalent function to format data in Javascript Object Notation
Upvotes: 1
Reputation: 14146
JSON. use json_encode()
to pass a php array containing your data back to the frontend.
Upvotes: 0
Reputation: 3144
you can use json and yeah it can be parsed easily if you transfer back json
try jquery .post method for example :
$.post("test.php", { "func": "getNameAndTime" },
function(data){
console.log(data.name); // John
console.log(data.time); // 2pm
}, "json }
Upvotes: 2