将 HTML ID 传递给 PHP/MySQL,接收'cannot read property __e3_ of undefined'



我正在制作一个Google地图,该地图将从数据库中提取信息并输出XML以解释为地图上的标记。我想将单击的元素ID传递到PHP中以过滤数据库结果。执行该功能后,我会遇到一个错误,说明"无法读取属性'_ e3 ''defined of Undefined''。当我摆脱变量并将类型直接输入代码时,一切正常。

相关jQuery

$(document).ready(function() {
        $('.map_item').toggle(
            function() {
                var itemid = this.id;
                $.ajax({
                    type: 'POST',
                    //php script takes info from database, outputs xml
                    url:'SQL.php',
                    //pass var to the php to select only items matching this id
                    data: 'variable1=' + itemid,
                    success: function(data) {

来自文件sql.php

的相关php
$ajax_var = $_POST['variable1'];
$query = 'SELECT * FROM location WHERE Type="' . $ajax_var . '"';
$result = mysql_query($query); //sqlsrv_query
header('Content-type: text/xml'); 
// Iterate through the rows, adding XML nodes for each
while ($row = @mysql_fetch_assoc($result)){   
// ADD TO XML DOCUMENT NODE  
$node = $dom->createElement('marker');  
$newnode = $parnode->appendChild($node);   
$newnode->setAttribute("dirtType",$row['dirtType']);
$newnode->setAttribute("lat", $row['lat']);  
$newnode->setAttribute("lng", $row['lng']);  
 } 
 echo $dom->saveXML();

我会说应该以不同的方式发送数据,例如:

data: {
   "variable1": itemId
}

相关内容

最新更新