87,904
社区成员
发帖
与我相关
我的任务
分享
switch ($_SERVER['HTTP_ORIGIN']) {
case 'http://from.com': case 'https://from.com':
header('Access-Control-Allow-Origin: '.$_SERVER['HTTP_ORIGIN']);
header('Access-Control-Allow-Methods: GET, PUT, POST, DELETE, OPTIONS');
header('Access-Control-Max-Age: 1000');
header('Access-Control-Allow-Headers: Content-Type, Authorization, X-Requested-With');
break;
}
本地JS端这样调用
$.ajax({
type: 'POST',
url: 'https://to.com/postHere.php',
crossDomain: true,
data: '{"some":"json"}',
dataType: 'json',
success: function(responseData, textStatus, jqXHR) {
var value = responseData.someKey;
},
error: function (responseData, textStatus, errorThrown) {
alert('POST failed.');
}
});
原文请参见
http://stackoverflow.com/questions/298745/how-do-i-send-a-cross-domain-post-request-via-javascript
$.ajax({
type: "POST",
url: url,
data: data,
success: success,
dataType: dataType
});
http://api.jquery.com/jquery.post/
jQuery.ajaxSetup({ jsonp: null, jsonpCallback: null});
$.post("http://127.0.0.1:8084/Demo/NewServlet", function(data){ alert(123); });
这样。
猜的。