如何让ajax在搜索输入上工作?

时间:2022-08-25 17:26:14

This is my code in the page:

这是我在页面中的代码:

<script type="text/javascript">

    function getSearch(str){

        if(str.length == 0){
        status.innerHTML =  'field is empty';
      }
if(u != "")
  {

        var se = new XMLHttpRequest();

urlencoded");

urlencoded的“);

      xmlhttp.onreadystatechange = function(){

        }
      }

  }
</script>

I am trying to make a live search so that when the person introduces a character in the input,it displays the movies from the database,the 'field is empty' and 'Verifying...' messages are displayed properly,but when i type something nothing changes insted of those messages.Can someone tell me please what can i do to fix it ?

我正在尝试进行实时搜索,以便当人在输入中引入一个字符时,它会显示数据库中的电影,“字段为空”和“验证...”消息正确显示,但是当我输入时什么都没有改变这些消息的内容。有人告诉我,我能做些什么来解决它?

In my console it says: Uncaught ReferenceError: xmlhttp is not defined

在我的控制台中它说:未捕获的ReferenceError:xmlhttp未定义

1 个解决方案

#1


4  

You have a typo in your js code: variable xmlhttp is not defined, you probably mean se instead. Try to replace

你的js代码中有一个拼写错误:变量xmlhttp没有定义,你可能意思是se。尝试更换

xmlhttp.onreadystatechange

by

通过

se.onreadystatechange

#1


4  

You have a typo in your js code: variable xmlhttp is not defined, you probably mean se instead. Try to replace

你的js代码中有一个拼写错误:变量xmlhttp没有定义,你可能意思是se。尝试更换

xmlhttp.onreadystatechange

by

通过

se.onreadystatechange