【发布时间】:2011-10-15 18:54:36
【问题描述】:
我尝试对此进行搜索,但找不到任何可以解决我的问题的方法。我想生成一个这样的网址来向我的网络服务发送请求:
http://localhost/jQueryStudy/RamagalHTML/processjson3.php?
path=update%2FtallyHdr&json=
{"SessionID":"hHuCG3Jt1um5gV7kE320Bw7EjG97I4qZ","operation":"add",
"transaction_date":"2011-7-29","supplier_id":"10000000108","wood_specie_id":"1",
"lines":[{"plank_number":"7","thickness":"5","width":"8","length_t":"8","quantity":"1","board_foot":"26.67","wood_classification_id":"1","price":"15"}],"scaled_by":"WER","tallied_by":"WE","checked_by":"WE","total_bdft":"580.00","final":"N"}
这是我现在拥有的当前 javascript 代码:
var dataJSON = {
"SessionID": $.cookie("SessionID"),
"operation": "add",
"transaction_date":$('#tallyDate').val(),
"supplier_id":$('#supplierInput').attr("name"),
"wood_specie_id":$('#woodSpecie').attr("name"),
"lines":plank_data,
"scaled_by":$('#tallyScaled').val().toUpperCase(),
"tallied_by":$('#tallyTallied').val().toUpperCase(),
"checked_by":$('#tallyChecked').val().toUpperCase(),
"total_bdft":$('#tallyTotal').val(),
"final":"N"
};
alert('this is the datajson from add : ' + JSON.stringify(dataJSON));
$.ajax({
type: 'POST',
data: dataJSON,
url: 'processjson2.php?path=update/tallyHdr',
dataType: primeSettings.ajaxDataType,
success: function(data) {
if ('error' in data)
{
showMessage('ERROR: ' + data["error"]["msg"]);
}
else{
$('#tblTallyHdr').trigger('reloadGrid');
}
}
});
我的 .php 代码是这样的:
<?php
$data_url = http_build_query (array('json' => $_REQUEST["json"]));
$data_len = strlen ($data_url);
echo file_get_contents("http://localhost:8001/" . $_REQUEST["path"], false, stream_context_create(
array (
'http' => array(
'method'=>'POST',
'header' => "Connection: close\r\nContent-Length: $data_len\r\n",
'content'=>$data_url
)
)
));
每次我运行我的程序,url 只是这个http://localhost/jQueryStudy/RamagalHTML/processjson2.php?path=update/tallyHdr,数据没有发布,这使得我的请求没有被执行。请帮助我。我不知道如何修复我的 php。
【问题讨论】:
-
POST信息在 URL 中的发送方式与GET不同。当你说你在 URL 中看不到它时,你是如何观察它的? -
在 firebug 中,我可以在控制台中看到我的 url 缺少我需要的数据。而且我还在编写 mmy webservce 代码的 delphi 程序中进行跟踪。我的 json 请求为空。