2011-10-28 17 views
0

任何人都可以提供一個簡單的例子來說明如何使用dojo對錶單進行ajax化並從php腳本中檢索結果?使用Dojo提交表單和檢索結果

<form action="login.php" method="post"> 
    <input type="text" name="user"> 
    <input type="password" name="password"> 
    <input type="button" value="login"> 
</form> 

+

<?PHP 
if($_POST["user"] == "test" && $_POST["password"] == "test") { 
    echo "youre logged in successfully [REDIRECT HERE]"; 
} 
else { 
    echo "you failed epic"; 
} 
?> 

+

dojo.xhrpost還是什麼?

+1

的StackOverflow是非常歡迎comunity。你不需要說你絕望或使用CAPS來獲得幫助... – hugomg

回答

4

xhrPOST - 例如

// Local var representing if the form has been sent at all 
var hasBeenSent = false; 
// Local var representing node to be updated 
var messageNode = dojo.byId("messageNode"); 
// Using dojo.xhrPost, as the amount of data sent could be large 
dojo.xhrPost({ 
    // The URL of the request 
    url: "submission.php", 
    // No content property -- just send the entire form 
    form: dojo.byId("contactForm"), 
    // The success handler 
    load: function(response) { 
     messageNode.innerHTML = "Thank you for contacting us!"; 
    }, 
    // The error handler 
    error: function() { 
     messageNode.innerHTML = "Your message could not be sent, please try again." 
    }, 
    // The complete handler 
    handle: function() { 
     hasBeenSent = true; 
    } 
}); 
+0

謝謝!我當然也看了一下文檔。但是我看不到php-script的輸出在哪裏被檢索到? – iceteea

+1

像這樣改變代碼 - 'load:function(response){message_ode_innerHTML = response; },'**響應**是你的PHP行:) –