在声明之前遗失的地方在哪里?

时间:2013-11-05 16:32:06

标签: javascript

在这个函数中,当我使用firebug时,我得到“syntaxerror:missing;在var url行上的语句之前。

    function makeRequest(){
                 var url= "contr_entry_pkg.sales_center_dropdown?&pnSalesCenterID=document.getElementById("pnSalesCenterID").value +&pvCurrCd='||CURRDEF||'";
                ajaxReq = (window.XMLHttpRequest)? new XMLHttpRequest() : new ActiveXObject("MSXML2.XMLHTTP")

                ajaxReq.open("POST",url ,true);
                ajaxReq.onreadystatechange =currencychange;         
                ajaxReq.send()         
        } 

2 个答案:

答案 0 :(得分:3)

尝试转义网址字符串中的"

var url= "contr_entry_pkg.sales_center_dropdown?&pnSalesCenterID=document.getElementById(\"pnSalesCenterID\").value +&pvCurrCd='||CURRDEF||'";

这将修复语法错误,虽然我认为你的意思是这样的:

var url= "contr_entry_pkg.sales_center_dropdown?&pnSalesCenterID=" + 
         document.getElementById("pnSalesCenterID").value +
         "&pvCurrCd='||CURRDEF||'";

此外,您应该(尽管并非严格要求)在每个陈述后放置分号:

ajaxReq = (window.XMLHttpRequest)? new XMLHttpRequest() : new ActiveXObject("MSXML2.XMLHTTP"); // <-- added ; here
...
ajaxReq.send(); // <-- added ; here

答案 1 :(得分:0)

function makeRequest(){
                 var url= "contr_entry_pkg.sales_center_dropdown?&pnSalesCenterID=document.getElementById(\"pnSalesCenterID\").value +&pvCurrCd='||CURRDEF||'";
                ajaxReq = (window.XMLHttpRequest)? new XMLHttpRequest() : new ActiveXObject("MSXML2.XMLHTTP")

                ajaxReq.open("POST",url ,true);
                ajaxReq.onreadystatechange =currencychange;         
                ajaxReq.send();      
        }