这正是我想传递给服务器的数据:
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2"
xmlns:gx="http://www.google.com/kml/ext/2.2"
xmlns:kml="http://www.opengis.net/kml/2.2"
xmlns:atom="http://www.w3.org/2005/Atom">
<Document>
<Placemark>
<name>model1</name>
<Model id="model_1">
<Location>
<longitude>-5.986926473546048</longitude>
<latitude>37.37725475811571</latitude>
<altitude>0</altitude>
</Location>
<Orientation>
<heading>0</heading>
<tilt>0</tilt>
<roll>0</roll>
</Orientation>
<Scale>
<x>1</x>
<y>1</y>
<z>1</z>
</Scale>
<Link>
<href>http://www.ihs.org/objects/streetlight.dae</href>
</Link>
<ResourceMap>
<Alias>
<targetHref>http://www.ihs.org/objects/streetlight/texture0.jpg</targetHref>
<sourceHref>streetlight/texture0.jpg</sourceHref>
</Alias>
<Alias>
<targetHref>http://www.ihs.org/objects/streetlight/texture1.jpg</targetHref>
<sourceHref>streetlight/texture1.jpg</sourceHref>
</Alias>
</ResourceMap>
</Model>
</Placemark>
<Placemark>
<name>model2</name>
<Model id="model_2">
<Location>
<longitude>-5.986969267031843</longitude>
<latitude>37.37727640316665</latitude>
<altitude>0</altitude>
</Location>
<Orientation>
<heading>0</heading>
<tilt>0</tilt>
<roll>0</roll>
</Orientation>
<Scale>
<x>1</x>
<y>1</y>
<z>1</z>
</Scale>
<Link>
<href>http://www.ihs.org/objects/streetlight.dae</href>
</Link>
<ResourceMap>
<Alias>
<targetHref>http://www.ihs.org/objects/streetlight/texture0.jpg</targetHref>
<sourceHref>streetlight/texture0.jpg</sourceHref>
</Alias>
<Alias>
<targetHref>http://www.ihs.org/objects/streetlight/texture1.jpg</targetHref>
<sourceHref>streetlight/texture1.jpg</sourceHref>
</Alias>
</ResourceMap>
</Model>
</Placemark>
</Document>
</kml>
我是通过ajax发布的,因此,
$.ajax({
type: "POST",
url:"/php/sendEdition.php?kml="+output,
async: true,
success: function(datos){
//datakml = eval(datos);
document.getElementById('dataOut').innerHTML = datos;
},
error: function (obj, error, objError){
alert("error");
}
});
这不管用。没有数据被发送到服务器。我认为,也许您不能仅仅通过ajax传递HTML标记;对吗?我不是在用表格,但没关系,因为我已经知道所有的信息了。
发布于 2014-01-20 05:05:04
你的问题是:
type: "POST",
url:"/php/sendEdition.php?kml="+output+",
首先,逗号后面的引号是语法错误。把它移开。
其次,将数据附加到URL中,这将生成一个类似于/php/sendEdition.php?kml=<?xml version="1.0"
的URL .您可以在这里立即看到一个问题,在XML数据中的问号和符号(和其他值)应该是URL转义,但不是。
您可以通过使用encodeURIComponent()
来修复这个问题,因此:
type: "POST",
url: "/php/sendEdition.php?kml=" + encodeURIComponent(output),
现在,您的XML将正确地转义。
但是,为什么要在URL中发送XML呢?这是一个帖子请求,有一个帖子体。更好的方式是用这种方式发送大量数据。
type: "POST",
url: "/php/sendEdition.php",
data: {"kml": output},
发布于 2014-01-19 11:39:49
您正在尝试将指向文件的指针存储到数据库中,这是不可能的。相反,您应该将文件的内容存储到数据库中。
mysql_query("INSERT INTO places_edited (id_user, user_name, user_pic_square, id_place, place_name, place_pic, latitude, longitude, kml, place_type, description)
VALUES ('$id_user', '$user_name', '$user_pic_square', '$id_place', '$place_name', '$place_pic', '$latitude', '$longitude', '$kml', '$place_type', '$description')");
您也可以创建一个临时文件并存储文件名,但是第一个选项更容易。
发布于 2014-01-19 11:50:04
在ajax调用中使用type: "POST"
,然后在PHP代码中尝试使用GET
访问它。
将您的PHP $_GET
超全局值改为$_POST
,如下所示:
$id_user=$_POST['id_user'];
$user_name=$_POST['user_name'];
$user_pic_square=$_POST['user_pic_square'];
$id_place=$_POST['id_place'];
$place_name=$_POST['place_name'];
$place_pic=$_POST['place_pic'];
$latitude=$_POST['latitude'];
$longitude=$_POST['longitude'];
$kml=$_POST['kml']; //THIS ONE IS THE BLOB FIELD
$place_type=$_POST['place_type'];
$description=$_POST['description'];
等
希望这能有所帮助。
另外,查看一下PHP文档--不再使用mysql_
函数,而是使用mysqli_
或PDO。这不是你的问题,只是个建议。
W3Schools为PHP和MySQL教程提供了一个很好的起点。
https://stackoverflow.com/questions/21221593
复制相似问题