Hello I am completely confused between json and ajax. When would what be used. I work with PHP on the server side. I regularly use ajax to receive data asynchronously, without invoking a page load. I use php’s json functions to pass data to javascript. But I just started learning jQuery, and I am completely confused when to use function ajax and when to use json. Can somebody help me out with this, thanks.
Share
I assume you are referring to the jQuery
.getJSON()method.This method is simply a shorthand way of using the jQuery
.ajax()method with JSON data..getJSON()is equivalent to:So, you can make use of
.getJSON()if you will be retrieving JSON data from the server. The data will automatically be parsed with thejQuery.parseJSON()method.In more general terms AJAX is a way to asynchronously retrieve information from a server. JSON is a way to format data…. but I assume you knew this already, and you were asking specifically about the two jQuery methods I mentioned.