我試圖爲我的窗戶,營造了登錄頁面8的應用程序,我使用HTML5和JavaScript ..所以儘量選用winjs.xhr張貼什麼是在文本框爲變量到一個特定的URL這是一個PHP腳本,所以這是我的例子中的網址「http://example.com/api/username=username&password=password」正在使用winjs.xhr將這些變量發佈到網址,但即使在console.log中也沒有得到任何響應使用WinJS.xhr張貼變量到URL
這是我的代碼
<script>
function handlelogin(){
document.getElementById("box").onsubmit = function(){
if(document.getElementById("email_address").value ==""){
document.getElementById("errormessage").innerHTML= "Please Provide Your Email Address";
return false;
}else{
var email_address = document.getElementById("email_address");
var password = document.getElementById("password");
var formparams = "?username=" + email_address.value + "&password=" + password.value;
document.getElementById("errormessage").innerHTML = "";
WinJS.xhr({type: "POST",
url: "http://example.com/api/",
data: formparams,
headers: { "Content-type": "application/x-www-form-urlencoded" }
}).then(
function (success) {
console.log(success.statusText);
if(success == 1703){
WinJS.Navigation.navigate("home.html");
}
},
function (error) {
console.log(error);
}
);
}
};
}
window.onload = function() {
handlelogin();
}
</script>
<form id="box" method="post" name="loginform">
<p>Email address</p>
<div class="email_address"><input type="text" id="email_address" /></div>
<p>Password</p>
<div class="password"><input type="password" id="password" /></div>
<p><span id="errormessage"></span></p>
<div class="button"><input type="submit" id="login" value="Sign In"/></div>
<p>ForgotPassword?</p>
</form>
你確定你其實並不意味着有網址在WinJS.xhr請求包括形式參數的拉'{類型:「後',網址:'http://考試ple.com/api/」 + formparams,頭:...}'? – GotDibbs 2013-04-29 19:15:22
您是否嘗試過放置斷點並進行調試?儘管代碼還存在其他問題 - 請求會到達example.com,並有200個響應。 – Sushil 2013-04-30 03:47:52