解决“No 'Access-Control-Allow-Origin' header is present on the requested resource”

1. Problem description

Use ajax request in js to print the following error message under the web console:

XMLHttpRequest cannot load http://192.168.2.46:8000/account/getjson/. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:63342' is therefore not allowed access.

My ajax code is as follows

var jsontree = [];
$.ajax({
    url: "http://192.168.2.46:8000/account/getjson/",
    type: "GET",
    dataType: 'JSON',
    success: function(result){
        jsontree = result;
    }
});
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

2. Solution

dataType: 'JSON'Replace the above with dataType: 'JSONP'.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326298538&siteId=291194637