0

我需要一些关于下面代码的帮助。我单独调试了 ajaxcomplete 以适应更高版本的 1.9.1。当我单独使用 Ajaxcomple 例程时,它确实有效,一切都很完美。当我单独使用 Autocomple 例程时,一切都很完美。当两者在一起时,它看起来确实不会触发 AjaxComplete。

<link rel="stylesheet" type="text/css" href="style.css" />
<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.1/themes/base/minified/jquery-ui.min.css" type="text/css" /> 
<script src="gen_validatorv4.js" type="text/javascript"></script>
<script type="text/javascript" src="http://code.jquery.com/ui/1.10.1/jquery-ui.min.js">    
<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.min.js">
<SCRIPT type="text/javascript">
pic1 = new Image(16, 16); 
pic1.src = "loader.gif";
$(document).ready(function(){
$("#username").change(function() { 
var usr = $("#username").val();
if(usr.length >= 4)
{
$("#status").html('<img src="loader.gif" align="absmiddle">&nbsp;Verification of disponibility...');
    $.ajax({  
    type: "POST",  
    url: "check.php",  
    data: "username="+ usr,  
    success: function(msg){  
      $(document).ajaxComplete(function(event, request, settings){ 
    if(msg == 'OK')
{ 
    $("#username").removeClass('object_error'); // if necessary
    $("#username").addClass("object_ok");
    $("#status").html('&nbsp;<img src="tick.gif" align="absmiddle">');
}  
else  
{  
    $("#username").removeClass('object_ok'); // if necessary
    $("#username").addClass("object_error");
    $(this).html(msg);
}  
  });
 }    
  }); 
}
else
        {
    $("#status").html('<font color="red">Email should be less than <strong>4</strong> characters.</font>');
    $("#username").removeClass('object_ok'); // if necessary
    $("#username").addClass("object_error");
    }

});
});
</SCRIPT>

    <form action='' method='post'>
  <table width="700" border="0"> 
    <tr>
      <td width="200"><div align="right">Courriel*:&nbsp;</div></td>
      <td width="100"><input id="username" size="20" type="text" name="Courriel"></td>
      <td width="400" align="left"><div id="status"></div></td>
    </tr> 
    </table>
        <p><label>Country:</label><input type='text' name='country' value='' class='auto'></p>
    </form>

<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.min.js">   </script>
<script type="text/javascript" src="http://code.jquery.com/ui/1.10.1/jquery-ui.min.js"></script>    
<script type="text/javascript">
$(function() {

    //autocomplete
    $(".auto").autocomplete({
        selectFirst:true,
        source: "Search_bon.php",
        delay: 0,
        autoFocus: true,
        minLength: 1
    });                

});
</script>
</body>
4

1 回答 1

0

尝试input使用自动完成change事件触发:

//autocomplete
$(".auto").autocomplete({
    selectFirst:true,
    source: "Search_bon.php",
    delay: 0,
    autoFocus: true,
    minLength: 1,
    change: function (event, ui){
        $("#username").trigger("change");
   }
}); 

还:

确保函数中的路径url: "check.php",正确.ajax。如果它不在根目录下,请尝试url: "/check.php",

于 2013-07-07T19:31:08.320 回答