Php Javascript变量在空格后被截断

Php Javascript变量在空格后被截断,php,javascript,string,variables,Php,Javascript,String,Variables,我有一个PHP页面,我正在使用JavaScript根据MySQL结果更新下拉列表。我的问题是,当我通过JavaScript变量传递客户名称时,它会在第一个空格处中断。例如:“家得宝”将显示为“家”,或“家得宝”显示为“The”。为了执行正确的查询,我希望传递整个字符串 以下是我表格中的相关代码: function getXMLHTTP() { //function to return the xml http object var xmlhttp=false;

我有一个PHP页面,我正在使用JavaScript根据MySQL结果更新下拉列表。我的问题是,当我通过JavaScript变量传递客户名称时,它会在第一个空格处中断。例如:“家得宝”将显示为“家”,或“家得宝”显示为“The”。为了执行正确的查询,我希望传递整个字符串

以下是我表格中的相关代码:

    function getXMLHTTP() { //function to return the xml http object
        var xmlhttp=false;  
        try{
            xmlhttp=new XMLHttpRequest();
        }
        catch(e)    {       
            try{            
                xmlhttp= new ActiveXObject("Microsoft.XMLHTTP");
            }
            catch(e){
                try{
                xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
                }
                catch(e1){
                    xmlhttp=false;
                }
            }
        }

        return xmlhttp;
      }


    function getCustCont(cID)
    {
    var strURL="Includes/cdd.php?custid="+cID;
    var req = getXMLHTTP();
    if (req)
    {
      req.onreadystatechange = function()
      {
       if (req.readyState == 4)
       {
     // only if "OK"
     if (req.status == 200)
          {
        document.getElementById('Contdiv').innerHTML=req.responseText;
     } else {
        alert("There was a problem while using XMLHTTP:\n" + req.statusText);
      }
        }
       }
    req.open("GET", strURL, true);
    req.send(null);
    }

//VARIABLES DEFINED AND START OF FORM

    <td width="60%">

    <select name="Customer" onchange="getCustCont(this.value)">
    <option value="SAC">Select Customer</option>
    <?php
    $i=0;
    while ($i < $num) {
    $Name=mysql_result($result,$i,"Name");

    echo "<option value=$Name>$Name</option>";
    $i++;
    }       
    ?>  

    </select>
    </td>
function getXMLHTTP(){//function返回xml http对象
var xmlhttp=false;
试一试{
xmlhttp=新的XMLHttpRequest();
}
第(e)款{
试试{
xmlhttp=新的ActiveXObject(“Microsoft.xmlhttp”);
}
捕获(e){
试一试{
xmlhttp=新的ActiveXObject(“Msxml2.xmlhttp”);
}
渔获物(e1){
xmlhttp=false;
}
}
}
返回xmlhttp;
}
函数getCustCont(cID)
{
var strURL=“Includes/cdd.php?custid=“+cID;
var req=getXMLHTTP();
如果(请求)
{
req.onreadystatechange=函数()
{
如果(req.readyState==4)
{
//只有在“OK”的情况下
如果(请求状态==200)
{
document.getElementById('Contdiv').innerHTML=req.responseText;
}否则{
警报(“使用XMLHTTP:\n“+req.statusText时出现问题”);
}
}
}
请求打开(“获取”,strURL,true);
请求发送(空);
}
//定义的变量和表单的开始
选择客户
cdd.php文件包括以下内容:

  <? 
    $Cust_ID = $_GET['custid'];
    include('../Includes/TrackingDB.php');

    mysql_connect($dbhost,$dbuser,$dbpass) or die('Error connecting to mysql');
    mysql_select_db($dbdb) or die('Error connecting to database');

    $query="SELECT t1.ContName FROM Cust_Contacts t1 INNER JOIN Customer_Listing t2 ON t1.Cust_ID = t1.Cust_ID WHERE t2.Name = '$Cust_ID'";
    $result=mysql_query($query);

    mysql_close();

    echo var_dump($Cust_ID); //I added this solely for the purposes of trouble shooting this issue. This is where I am seeing the truncated string.

    ?>
    <select name="Cust_Buyer" onchange="getCity(<?=$country?>,this.value)">
    <? while($row=mysql_fetch_array($result)) { ?>
    <option value="<?=$row['ContName']?>"><?=$row['ContName']?></option>
    <? } ?>
    </select>


同样,在cdd.php文件中,字符串在空白处截断。

encodecID

var strURL="Includes/cdd.php?custid="+encodeURIComponent(cID);
并用引号将值括起来:

echo "<option value='$Name'>$Name</option>";
echo“$Name”;

您是一位绅士和学者……工作得很有魅力。谢谢!