Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/226.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 对服务器的ajax JSON请求type=POST(安全登录请求)_Php_Json - Fatal编程技术网

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

Php 对服务器的ajax JSON请求type=POST(安全登录请求),php,json,Php,Json,要通过JavaScript普通提交-而不是jQuery。。。 对服务器的ajax JSON请求type=POST(安全登录请求)所需的web表单 没有网页表单怎么办。。。JSON发送的字符串var放在哪里,以及php中的how/what ajax3.send(jsonStringhere);/???如何在php中获得最佳效果 function loginProcess() { var userID = document.getElementById( "name" ).value; var em

要通过JavaScript普通提交-而不是jQuery。。。 对服务器的ajax JSON请求type=POST(安全登录请求)所需的web表单

没有网页表单怎么办。。。JSON发送的字符串var放在哪里,以及php中的how/what

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,可能不希望他们的个人信息隐藏在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);

我将投票支持那些理解任何关于OPs问题的答案的人。你需要对所有参数进行URL编码(如果密码或JSON包含
&
)。