Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/415.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/gwt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在声明之前,丢失的在哪里?_Javascript - Fatal编程技术网

Javascript 在声明之前,丢失的在哪里?

Javascript 在声明之前,丢失的在哪里?,javascript,Javascript,在这个函数中,当我使用firebug时,我在var url行上得到“syntaxerror:missing;before”语句 function makeRequest(){ var url= "contr_entry_pkg.sales_center_dropdown?&pnSalesCenterID=document.getElementById("pnSalesCenterID").value +&pvCurrCd='||CURRD

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

    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()         
        } 
尝试转义url字符串中的

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

ajaxReq=(window.XMLHttpRequest)?新的XMLHttpRequest():新的ActiveXObject(“MSXML2.XMLHTTP”);//在函数调用中,使用单引号或转义那些双引号Stack Overflow的语法highlighter提供了一个很好的线索。我希望您的编辑器有语法突出显示;-)
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();      
        }