[XMLHttpRequest] Cross-domain Ajax REST request + No ‘Access-Control-Allow-Origin’ header is present on the requested resource

Context :

In summary, this article is to record the solution for an “No ‘Access-Control-Allow-Origin’ header is present on the requested ressource” error.

My local domain is : localhost, in which based my local application

My request domain is : http://www.example.com, which is write in PHP, and will return a simple object in JSON
Such as : {"return":"OK"}

Continue reading


[jQuery] Comparison of getJSON and ajax

Comparison of jQuery getJSON and ajax.

I tried to debug this code in jQuery(the following), the object is to get the data from a json file and re-format the output data into an array, this array will be used in others functions later.

$(document).ready(function() {
  var arr = [];
  // Get data from a json file
  $.getJSON("jsonfile.json", {}, function(data) {
    $.each(data, function(key, value) {
      arr.push(value); // Add data value to an array
  console.log(arr); // Print the array to console

Continue reading