我有一个javascript数组,我想发布到php存储到oracle varchar2。我想知道如何在php中获取此数组。现在我总是有一个字符串[object Object]而不是oracle中的数组。我使用JQuery $ .post将变量发送到php,如下所示:
function savePolygons(){
$.get('oracle_deletePolygons.php');
for (var i = 0; i < createdShapes.length; i++){
var nom_zone = escape(document.getElementById('nom_zone_' + createdShapes[i].id).value);
var couleur = escape(createdShapes[i].fillColor);
var code_cs = escape('711');
var shapeid_export = escape(createdShapes[i].id);
var geometry = createdShapes[i].getPath();
alert(geometry)
var url1 = "oracle_savePolygons.php?nom_zone=" + nom_zone + "&couleur=" + couleur + "&code_cs=" + code_cs + "&shapeid_export=" + shapeid_export + "&geometry=" + geometry;
$.get(url1);
}
}
在php中:
<?php
require("oracle_dbinfo.php");
sleep(5);
$nom_zone =$_GET['nom_zone'];
$shapeid_export = $_GET['shapeid_export'];
$code_cs = $_GET['code_cs'];
$couleur = $_GET['couleur'];
$geometry = $_GET['geometry'];
$conn = oci_connect($username, $password, $database);
$query = oci_parse($conn, 'INSERT INTO test1 (nom_zone, shapeid, code_cs, couleur, geometry) VALUES (:nom_zone, :shapeid_export, :code_cs, :couleur, :geometry)');
oci_bind_by_name($query, ":nom_zone", $nom_zone);
oci_bind_by_name($query, ":shapeid_export", $shapeid_export);
oci_bind_by_name($query, ":code_cs", $code_cs);
oci_bind_by_name($query, ":couleur", $couleur);
oci_bind_by_name($query, ":geometry", $geometry);
oci_execute($query);
oci_commit($conn);
?>
var几何是多边形每个顶点的坐标数组。
答案 0 :(得分:1)
如果您没有向网址发布任何数据,请使用$ .get():
$.get('oracle_deletePolygons.php');
请参阅jQuery.get()
另请注意,这很可能是使用$ .get(),因为您只是发送查询字符串:
var url1 = "oracle_savePolygons.php?nom_zone=" + nom_zone + "&couleur=" + couleur + "&code_cs=" + code_cs + "&shapeid_export=" + shapeid_export + "&geometry=" + geometry;
$.post(url1);
请改为尝试:
var url1 = "oracle_savePolygons.php?nom_zone=" + nom_zone + "&couleur=" + couleur + "&code_cs=" + code_cs + "&shapeid_export=" + shapeid_export + "&geometry=" + geometry;
$.get(url1);
使用$.get()发布数据的示例:
$.get('oracle_savePolygons.php', {
'num_zone' : nom_zone,
'couleur' : couleur,
'code_cs' : code_cs,
'shapeid_export' : shapeid_export,
'geometry' : geometry
}, function (data) {
//Success callback if you need it
});