function test(){
var json1 = {
"name":"John",
"type":"Infinite",
};
var result = submit();
document.getElementById('title').innerHTML = result;
}
function submit(data){
var xmlhttp;
window.XMLHttpRequest?xmlhttp=new XMLHttpRequest:xmlhttp=ActiveXObject('MicrosoftXMLHTTP');
xmlhttp.onreadystatechange = function(){
if(xmlhttp.readyState == 4 && xmlhttp.status == 200){
console.log("Everything in Server side goes well!");
//document.getElementById('title').innerHTML = xmlhttp.responseText;
return xmlhttp.responseText;
}
}
xmlhttp.open('GET','http://johnkreed.ns1.cscces.net/echo.php?data='+data, true);
xmlhttp.send();
}
这种方式将json数据发送到服务器端不知道可不可以,服务器端的PHP我也不知道怎么验证。只知道返回过来的数据在网页上显示“undefined".
正确的应该怎么做?