In previous post about JSON Requests and Responses we learn how to send JSON request to our server-side scripts and return a JSON response.
Now back on the client, after the server has done what it needs to do, the response is set in the responseText property of the XMLHttpRequest object. Once the readyState and status are set to 4 and 200, respectively, the JSON string can be saved and eval( ).
Here is the code that handles in getting the JSON string and ready to parse.
Continue reading ‘Parsing JSON String’
In the previous post about JSON, you know what JSON is and you see what JSON looks like and how it differs to XML.
Now, you are about to learn how to handle JSON Requests and Responses. Before we get started you need to have Zend Framework installed and running in you local webserver in order for you to run the sample code.
Requests to the server using Ajax and JSON are the same as with XML.
function requestData(request, url, data, func, method) {
if (request) {
if (method == 'GET')
request.open('GET', url + '?' + data, true);
else
request.open('POST', url, true);
request.onreadystatechange = func;
if (method == 'GET')
request.send('');
else
request.send(data);
}
}
Continue reading ‘JSON Requests and Responses’
In a past few weeks, most of my projects handled involved XML manipulation and AJAX. And because of that I found an alternative to the XML which is more lightweight and can be easily used together with your DOM. Its JSON.
JSON is a data exchange format that is a subset of the object literal notation in JavaScript. It has been gaining a lot of attention lately as a lightweight alternative to XML, especially in Ajax applications. Why is this? Because of the ability in JavaScript to parse information quickly using the eval( ) function. JSON does not require JavaScript, however, and you can use it as a simple exchange format for any scripting language.
Lets take a look what JSON looks like.
Continue reading ‘Getting started with JSON’