2012-12-28 94 views
0

要通過JavaScript提交簡單 - 不是jQuery ... ajax對服務器類型= POST(安全登錄請求)的JSON請求所需的Web表單?ajax對服務器類型= POST(安全登錄請求)的JSON請求

它怎麼沒有一個Web窗體...在哪裏把JSON發送字符串變種和如何/什麼得到在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 

//??? 

} 
+1

我會投票時從誰明白任何人,即使是遠程接近的有機磷農藥的問題.. – dbf

回答

2

你不應該通過URL(GET)來發送這樣的敏感信息。

人們經常分享網址,可能不希望他們的個人信息隱藏在內。

要模擬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); 
+0

任何回答您需要URL編碼的所有參數(如果密碼或JSON包含'&')。 – Barmar

+0

@Barmar謝謝,更新。 –

+0

現在你得到我的upvote! – Barmar