locked
ajax search javascript help!!! RRS feed

  • Question

  • Hello i have the following files

    body.html
    data.php
    js3.js

    I am trying to create an ajax search but it doesnt work....
    Pls some help..
    The js code is:
    1. var xmlHttp
    2. function finding(str){
    3. try {
    4. xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    5. } catch (e) {
    6. try {
    7. xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    8. }catch (e) {
    9. try {
    10. xmlhttp = new XMLHttpRequest()
    11. }catch (e) {
    12. alert("Browser does not support HTTP Request")
    13. return
    14. }
    15. var url="data.php"
    16. url=url+"?productname="+str
    17. url=url+"&sid="+Math.random()
    18. xmlHttp.onreadystatechange=stateChanged
    19. xmlHttp.open("GET",url,true)
    20. xmlHttp.send(null)
    21. }}}
    22. function stateChanged()
    23. {
    24. if(xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
    25. {
    26. document.getElementById("result").innerHTML=xmlHttp.responseText
    27. }
    28. }
    29. function stateChanged()
    30. {
    31. if(xmlHttp.readyState==4|| xmlHttp.readyState=="complete")
    32. {
    33. document.getElementById("result").innerHTML=xmlHttp.responseText
    34. }
    35. }
    36. function GetXmlHttpObject()
    37. {
    38. var xmlHttp=null;
    39. }


    The html code containes:
    1. <script src="js3.js"></script>
    2. </head>
    3. <body>
    4. <form>
    5. search:
    6. <input type="text" size="30" onkeyup="finding(this.value)"/>
    7. </form>
    8. <p><div id="Result"></div>
    9. </p>
    10. </body>
    11. </html>
    Tuesday, April 12, 2011 9:23 PM

All replies

  • what error is displayed?

    you can try

    if(xmlHttp.readyState==4)
    {
    if(xmlHttp.status == 200)
    {
    document.getElementById("result").innerHTML=xmlHttp.responseText
    }
    }


    【孟子E章】
    Thursday, April 14, 2011 6:31 AM