GET请求不会打开文件

时间:2011-07-15 20:43:52

标签: php javascript ajax get xmlhttprequest

我一直试图弄清楚为什么这个js代码有效,但是没有打开请求的文件。我使用FireFox的LiveHTTPHeader插件,它发送参数,一切似乎都应该工作,但我请求的php文件无法打开。可能有什么不对?我将不胜感激。谢谢。

PS:我要求它的文件名是正确的,所以不是那样。

//XMLHTTPRequest Enable
    function createBridge()
    {
        var request_type;
        var browser = navigator.appName;
        if(browser == "Microsoft Internet Explorer")
        {
            request_type = new ActiveXObject("Microsoft.XMLHTTP");

        }
        else
        {
            request_type = new XMLHttpRequest();

        }
        return request_type;
    }
        var http = createBridge();

    function requesting_search()
    {
        var user_inputs=[];
        user_inputs[0] = document.getElementById("faculty1").value;
        user_inputs[1] = document.getElementById("department1").value; 
        user_inputs[2] = document.getElementById("course1").value; 
        user_inputs[3] = document.getElementById("name1").value; 
        user_inputs[4] = document.getElementById("lastname1").value;
        var x=document.getElementById("order1").selectedIndex;
        var y=document.getElementById("order1").options;
        user_inputs[5] = y[x].text;

    if(user_inputs[0] != "" || user_inputs[1] != "" || user_inputs[2] != "" ||  user_inputs[3]!= "" || user_inputs[4] != "")    
    {
    var i;
    for(i=0; i<5; i++)
    {
        if(user_inputs[i] != "")
        {user_inputs[i] = encodeURIComponent(user_inputs[i]);}
    }

    var url = "prehp/search_db.php?faculty1=" + user_inputs[0] + "&department1=" + user_inputs[1] + "&course1=" + user_inputs[2] + "&name1=" + user_inputs[3] + "&lastname1=" + user_inputs[4]+ "&order1=" + user_inputs[5];
    http.open("GET", url , true);

    http.onreadystatechange = function()
    {
        if(http.readyState == 4)
    {   
        var answer = http.responseText;
        document.getElementById("insert_response").innerHTML = "* Llena solo la informaci&oacute;n que necesite buscar, Paso a php";
    }
    else
    {document.getElementById("insert_response").innerHTML = "Error";}
        }
    http.send(null);
    }
    else
    {document.getElementById("insert_response").innerHTML = "Por favor, llene al menos uno de los blancos para realizar su busqueda!";}
    }

0 个答案:

没有答案