ajax对服务器的JSON请求类型=POST(安全登录请求)


ajax JSON request to the server type=POST(secure log in request)

通过JavaScript plain提交-而不是jQuery…ajax JSON请求到服务器类型=POST(安全登录请求)所需的web表单?

如何做到没有web表单…JSON发送字符串var和如何/什么得到在php中?

ajax3.send (jsonStringhere);//? ?如何在php中获得??

function loginProcess() {
var userID = document.getElementById( "name" ).value;
var email = document.getElementById( "email" ).value;
var password = document.getElementById( "password" ).value;
ajax3 = new XMLHttpRequest();
//1st way
ajax3.open("GET","loginProcess.php?userID="+userID+"&email="+email+"&password="+password,false); 
ajax3.addEventListener("readystatechange", processResponse, true); 
ajax3.send();
changeDisplay("loginRegisterDiv");

//2nd way JSON post type here
//???
}

您不应该通过URL (GET)发送这样的敏感信息。

人们经常分享url,可能不希望他们的个人信息隐藏在其中。

要模拟web表单,请尝试发送POST请求。将JSON放到查询属性中:

var ec = window.encodeURIComponent,
    queryStr = "userID=" + ec(userID) + "&email=" + ec(email) + "&password=" + ec(password) + "&json" + ec(JSON.stringify(yourJson)),
    ajaxReq = new XMLHttpRequest();
ajaxReq.open("POST", "loginProcess.php", false);  // Should really be 'true' for asynchronous...
ajaxReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');  // Important!
ajaxReq.send(queryStr);