2017-06-03 16:11

jQuery Ajax函数不起作用?

  • php
  • ajax
  • javascript
  • jquery

I'm developing a simple login form for my website. And to do that I thought to use ajax to connect with php to validate users. However to do that I cannot get output from ajax.

 function submitForLogin() 
            type: "POST",
            url: "php/login.php",
            data: { email: "",password:"123" }}).done(function(data){alert(data);});



When user clicks on login button it calls submitForLogin() function.

Above part of the code I've placed in my login.html file. To validate whether this works or not I simply replaced data values of email and password with hard coded values.

Note : and 123 both email and password stored in Wamp server database.

This is the PHP file :

$servername ="localhost";
    //To create a connection
    $con = mysqli_connect($servername,$username,$password,$dbname); //check connection
        die("Connection failed: ".mysqli_connect_error());
    $sql="SELECT Email,Password FROM USERTABLE WHERE Email='".$userEmail."'";
        echo "userExist";
        echo "fakeUser";


Whenever I run php file only (with $userEmail and $userPass having previous hard coded values) php prints userExist output. But using ajax I cannot get that in an alert box.

Is there something I missing? I'm running the website in wamp server too.


When I check console errors it shows;

enter image description here

And when I click on login.html line 112, it shows;

enter image description here

And ideas guys? Also, none of the solutions provided so far gave me successful answer for the question.

There was a jquery error and now it's fixed. But syntax error exists.

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享