<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta http-equiv="「Access-Control-Allow-Origin" content="*" /> <title>ajax跨域</title> <script type="text/javascript" src="https://code.jquery.com/jquery-2.2.3.min.js"> </script> <script type="text/javascript"> $(function(){ $.ajax({ url: "http://localhost:8080/test/InitServelt?jsoncallback=?", type: "GET", processData:false, dataType: "jsonp", jsonp:"jsoncallback", jsonpCallback:"jsoncallback", headers:{"Access-Control-Allow-Origin":"*"}, success: function (data) { debugger; console.log(data); }, error: function (xhr, textStatus, errorThrow) { console.log(xhr); } }); }); </script> </head> <body> </body> </html>
jsoncallback({"a":"1"}) // 跨域的傳送的字符串與以前不得不同 必須用 jsoncallback()包裹起來