2012-08-05 43 views
1

我想從瀏覽器發送一個變量時,使用登錄到服務器。 我不能夠做到這一點......jquery post不調用php

PHP代碼:

<?php 
echo "test"; 
    $email = $_REQUEST['email'] ; 

    echo $email; 
?> 

html頁面:

<html> 
    <head> 
    <title>Demo</title> 
     <script src="http://code.jquery.com/jquery-latest.js"></script> 
    </head> 
    <body> 

    <script> 

      alert("test"); 

$.post("receiver.php", { email: "John", message: "2pm" })s; 


</script> 

</body> 
</html> 

能否請你讓我知道我錯過了什麼。看起來我缺少一些非常基本的東西.. 在php文件中的回聲測試也不打印

+2

'''。.post()'調用結束時的's'?使用您的瀏覽器控制檯來檢查JavaScript錯誤。 – tigrang 2012-08-05 00:45:26

+0

你不會看到回顯的值,因爲你沒有做任何事情。在瀏覽器的控制檯中觀看AJAX活動,並且您應該從PHP腳本的HTTP響應中看到電子郵件。 – 2012-08-05 00:46:06

回答

0

您需要定義一個函數來處理PHP返回的任何東西(你也有一個輕微的語法錯誤,如@tigrang說)。試試這個:

$.post("receiver.php", { email: "John", message: "2pm" }, function(data){ console.log(data);}); 
+0

謝謝修復問題 – 2012-08-05 01:30:16

+0

@PavanKumar很高興幫助! – SomeKittens 2012-08-05 01:30:48