JavaScript
Article

jQuery.ajax get json code snippet

By Sam Deering

Just a snippet i use often so thought i would post it for easy access. It basically just grabs a JSON from the same server (remember AJAX only works on the same server, unless you use JSONP or have a Proxy pass in place).

Read more about Ajax and JSON.

(function($) {
	$.ajax({
		type: 'GET',
		url: 'data/data.json',
		async: false,
		datatype: 'JSON',
		success: function(data)
		{
			if (data) 
			{
				console.log(data);
			}
		}
	});
})(jQuery);
Sam Deering
Meet the author
Sam Deering is a Front-end Web Developer who specialises in JavaScript & jQuery. Sam is driven and passionate about sharing his knowledge to educate others.

No Reader comments

Recommended

Learn Coding Online
Learn Web Development

Start learning web development and design for free with SitePoint Premium!

Get the latest in JavaScript, once a week, for free.