Jump to content

AJAX and JSON


jimfog

Recommended Posts

I wanted to know the following: JSON data are the data returned by the server, upon an AJAX request made by the client. If that is wrong, correct me. When the client makes an AJAX request to the server, are JSON data sent also? Resuming, is JSON sent in both directions? From client to server AND from server to client? Thanks.

Link to comment
Share on other sites

Server can may be return JSON data or may not. It depends on what is told to server to serve. JSON is way of representing data.http://json.org

Link to comment
Share on other sites

In a web application, using JSON is your option. You can choose to have the server send and receive data in JSON format. JSON is just a syntax. You could use XML, or just a string with delimiters. It doesn't matter how the data is sent as long as you programmed both sides to understand what's being sent and received.

Link to comment
Share on other sites

Ok, i got the picture now. You see, i thought that a server can only send JSON, but not receive(from a client). And another thing, since there are other ways to send data, why JSON has become so prevalent nowadays.

Link to comment
Share on other sites

JSON is fast and easy to deal with. It's an easy way to transfer a certain data structure, like an array, from Javascript to a language like PHP and vice-versa. When I need to submit complex data to the server I use a JSON structure so that PHP can decode that into an array that it can use.

Link to comment
Share on other sites

it's very lightweight (it's just text/string) and is easily readable by both computers and developers. because of that, it is easily implemented in many languages, thus making it easier to use as a data exchange format. if you read the top of the page that birbal posted for you, it is pretty much covered right there.

JSON (JavaScript Object Notation) is a lightweight data-interchange format. It is easy for humans to read and write. It is easy for machines to parse and generate. It is based on a subset of the JavaScript Programming Language, Standard ECMA-262 3rd Edition - December 1999. JSON is a text format that is completely language independent but uses conventions that are familiar to programmers of the C-family of languages, including C, C++, C#, Java, JavaScript, Perl, Python, and many others. These properties make JSON an ideal data-interchange language.
Link to comment
Share on other sites

so you could write a form using the post method and instead of sending the data with "classical way", send it with Json and Ajax request. Is the above example representative of Ajax.

Link to comment
Share on other sites

Sort of. you could send your POST data as JSON via an AJAX request, but since POST/GET data is sent as NVP's (name value pairs), you would have to use, jQuery for example to take an object and serialize it into NVP'S for you though. jQuery has awesome methods for taking an entire form and creating the NVP's for you for this specific purpose. Typically JSON is what is returned as the request and then turned into an acceptable data structure for calling language. AJAX is just a technique for creating an independent HTTP request to the server.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...