2017-04-04 79 views
1

AJAX代碼: -AJAX請求不做

$("#email").change(function(){ 
    alert('email changed'); 
    var Email = { 
     email: $('#email').val() 
    } 
    var formsubmission = 'http://127.0.0.1/heropet/Common/check_mail'; 
    $.ajax({ 
    method: "POST", 
    url: formsubmission, 
    data: Email, 
    success: function(response){ 
     alert(response); 
    } 
    }); 

HTML代碼:

<label>E-mail</label> 
<input type="text" name="email" id="email" value=""><br> 

我不知道,但在XAMPP網絡服務器,它不會使AJAX請求。我該如何解決這個錯誤?對於我弱小的英語感到抱歉。

+0

你得到任何類型的錯誤? –

+0

@ExplosionPills sir no –

+0

Uncaught TypeError:$ .ajax不是函數 –

回答

1

錯誤: -

1.closing });錯過的$("#email").change(function(){

工作示例代碼: -

$("#email").change(function(){ 
 
    alert('email changed'); 
 
    var Email = $('#email').val(); 
 
    var formsubmission = 'http://127.0.0.1/heropet/Common/check_mail'; 
 
    $.ajax({ 
 
    method: "POST", 
 
    url: formsubmission, 
 
    data: {email:Email}, 
 
    success: function(response){ 
 
     alert(response); 
 
    } 
 
    }); 
 
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<label>E-mail</label> 
 
<input type="text" name="email" id="email" value=""><br>

注: - 增加一個適當的jQuery庫,因爲我已添加到我的示例中。

0

您在最後缺少"})"

而且把它包在$(document).ready(function(){})

如下圖所示:

$(document).ready(function(){ 
    $("#email").change(function(){ 
     alert('email changed'); 
     var Email = { 
      email: $('#email').val() 
     } 
     var formsubmission = 'http://127.0.0.1/heropet/Common/check_mail'; 
     $.ajax({ 
      method: "POST", 
      url: formsubmission, 
      data: Email, 
      success: function(response){ 
       alert(response); 
      } 
     }); 
    }); 
});