What is the preferred way to do AJAX.
If it was for a search page written in PHP using Jquery for the AJAX
How would you handle the response
a) Have the response contain all the relevant html/styling
or
b) Send pure JSON and have a javascript function build the html/styling around the javascript variables.
I can see advantages to both. 'a' is obviously easier whilst 'b' is more efficient (although gzip would probably make the difference negligible).
JSON stores all the data in an array so data transfer makes easier. That's why JSON is the best for sharing data of any size even audio, video, etc. Its syntax is very easy to use.
Javascript is the language itself so you should learn it first. JSON is the javascript object notation so while you're learning Javascript you will be learning it too. Ajax is the API for async calls to the server so it has its own object which is consumed using JS.
According to the AJAX model, web applications can send and retrieve data from a server asynchronously without interfering with the display and the behavior of the existing page. Many developers use JSON to pass AJAX updates between the client and the server.
Despite that AJAX stands for Asynchronous JavaScript and XML, JSON is frequently used for sending and retrieving data from the server. JSON stands for JavaScript Object Notation. JSON is a data format that very close to a JavaScript object, except that it can't contain any functions or dynamic code.
I would go with the html:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With