在不同浏览器的桌面版本上,一切正常,两种方法都有效。但在手机上,没有一个工作。页面已完全加载,没有错误,所有内容也在移动版本上加载。只有数据不被传输。你怎么能决定?
$(document).ready(function(){
var user = ''; // name
var user2 = ''; // email
var x = localStorage.getItem("memberarea_profile");
var x2 = JSON.parse(x);
var x3 = window.location; // current url
var dataString = 'email='+user2+'&name='+ user+'&page='+ x3;
$.ajax({
type: 'POST',
url: 'https://server',
crossDomain: true,
data: dataString,
success: function(responseData, textStatus, jqXHR) {
},
error: function(xhr, status, error) {
var err = eval("(" + xhr.responseText + ")");
alert(err.Message);
}
});
function getXmlHttp(){
var xmlhttp;
try {
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (E) {
xmlhttp = false;
}
}
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
xmlhttp = new XMLHttpRequest();
}
return xmlhttp;
}
var xhr = getXmlHttp();
//var xhr = new XMLHttpRequest();
xhr.open("POST", '//server', true);
xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhr.onreadystatechange = function() {
if(xhr.readyState == XMLHttpRequest.DONE && xhr.status == 200) {
alert('Done');
}
}
xhr.send(dataString);
});
<?php
switch ($_SERVER['HTTP_ORIGIN']) {
case 'http://server': case 'https://server':
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;
}
?>