在这里真的很挣扎,我相信这很简单。我正在尝试使用xmlhttp和PHP后端从移动APP上传一些数据。
首先尝试使用以下JavaScript;
<script>
function sendData()
{
var xmlhttp = new XHRObject();
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
xmlhttp.responsetext will have what is sent back - use Print_R in php
document.getElementById('ResponseDiv').innerHTML = "Entry Posted";
}
}
var d = new Date();
var n = d.toLocaleString(d);
var uid = intel.xdk.device.uuid;
var postdata = '{';
postdata += '"SBP_VehicleReg": "' + document.getElementById('VehicleReg').value + '"';
postdata += ',"SBP_Uuid": "' + uid + '"';
postdata += ',"SBP_PostedDate": "' + n + '"';
postdata += ',"SBP_Category": "' + document.getElementById('Category').value + '"';
postdata += ',"SBP_Details": "' + document.getElementById('Details').value + '"';
postdata += '}';
xmlhttp.open("POST","http://sxxxx.co.uk/SBPostPost.php", false);
xmlhttp.setRequestHeader("Content-type","multipart/form-data");
xmlhttp.send(postdata);
}
</script>
&#13;
....使用Debug我得到以下显示为POSTed; (对我来说看起来不错)
Request URL:http://sxxxx.co.uk/SBPostPost.php
Request Method:POST
Status Code:200 OK
Request Headers
Provisional headers are shown
Content-type:multipart/form-data
Origin:http://127.0.0.1:58889
Referer:http://127.0.0.1:58889/http-services/emulator-webserver/ripple/userapp/x/C/Users/Phils/AppData/Local/XDK/xdk-scratchdir/e14eb410-7cf2-4bed-ba25-515e6df98e8c/platforms/ios/www/index.html
User-Agent:Mozilla/5.0 (iPhone; CPU iPhone OS 8_0 like Mac OS X) AppleWebKit/600.1.3 (KHTML, like Gecko) Version/8.0 Mobile/12A4345d Safari/600.1.4
X-DevTools-Emulate-Network-Conditions-Client-Id:4F9909BD-1710-45D3-874E-7CE5AB421AA8
Request Payload view source
{SBP_VehicleReg:abcdefghij, SBP_Uuid:A86780BE-4F09-4428-8BF6-05A59B422126,…}
SBP_Category: "Opt1"
SBP_Details: "details of the POST"
SBP_PostedDate: "15/09/2015 12:44:33"
SBP_Uuid: "A86780BE-4F09-4428-8BF6-05A59B422126"
SBP_VehicleReg: "abcdefghij"
Response Headers
Content-Encoding:gzip
Content-Length:513
Content-Type:text/html
Date:Tue, 15 Sep 2015 11:44:30 GMT
Server:Microsoft-IIS/8.5
Vary:Accept-Encoding
&#13;
但是当我尝试将字段输出时 - 使用以下PHP - 我什么也得不到; 尝试了各种各样的事情;
*$headers = getallheaders();
while (list($header, $value) = each($headers)) {
echo "$header: $value<br>\n";*
这回应了标题
*if ($headers["Content-Type"] == "multipart/form-data") {
echo "SUCCESS";
}*
以“成功”
作为回应 *foreach ($_POST as $param_name => $param_val) {
echo "Param: $param_name; Value: $param_val<br />\n";
}*
但这没有任何意义;
*echo $_POST['SBP_Uuid'];*
这给出了未定义变量SBP_Uuid
任何想法??
菲尔
答案 0 :(得分:0)
您可以使用var_dump($_POST)
查看收到的所有数据,然后检查您是否使用了错误的密钥。