我需要帮助将表示多边形的复杂字符串传递给php脚本,其中字符串用于SQL查询。正确的格式是将整个POLYGON语句用单引号括起来。 PHP脚本没有捕获$_POST
变量。可能是什么原因?
使用Javascript:
var polyBoundary = "'POLYGON ((-98.13787244260311 30.031055426540206, -95.98455213010311 31.970803930433096, -92.18328259885311 27.89734922968426, -95.69890759885311 26.49024045886963, -98.13787244260311 30.031055426540206))'";
$.post("php/insertPolygon.php", {boundary: polyBoundary}, function (data) {
alert(data) // this alert never fires
// Do stuff with the response
}, "json");
PHP:
<?php
$prjBoundary = $_POST['boundary']; # I'll sanitize once I get everything working
# Connect to DB, execute SQL query, etc.
# Make sure I'm sending a response no matter what
if ( ($errors = sqlsrv_errors() ) !=null) {
echo "Error!";
} else {
echo "SUCCESS!"; # this should have been echo json_encode("SUCCESS!");
}
PHP错误:Undefined index: boundary in FILENAME on line 2