[英]HTTP Error in my POST data
This question is a continuation to this previous question of mine in here. 这个问题是这里先前我的问题的延续。
I have this HTTP: Error
in my previous code due to query strings that is more than the limit to be send in the url to my webservice (that was what I understand). 我的先前代码中存在此
HTTP: Error
,原因是查询字符串超出了要发送到我的Web服务的url中的限制(这是我的理解)。 I was using method Get
before and I was told by kleinohad to use method POST
. 我以前使用过
Get
方法,并且kleinohad告诉我要使用POST
方法。 Now, I am using POST
but still have an error like the one I have in method GET
, which is the 'HTTP: Error' everytime I have lots of post data
to be send to the url, (it will not get through my webservice.). 现在,我正在使用
POST
但是仍然有错误,就像我在GET
方法中遇到的错误一样,每当我有很多要发送到url的post data
,它就是“ HTTP:错误”(它将无法通过我的Web服务获取) )。
Here is my javascript code: 这是我的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?' + $.param({path:'update/tallyHdr',json:JSON.stringify(dataJSON)}),
dataType: primeSettings.ajaxDataType,
success: function(data) {
if ('error' in data)
{
showMessage('ERROR: ' + data["error"]["msg"]);
}
else{
$('#tblTallyHdr').trigger('reloadGrid');
}
}
});
And here is my .php code (thanks to SMka): 这是我的.php代码(感谢SMka):
<?php
//this is already running code but could not accept large query string
$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
)
)
));
?>
My question is, why I can't still send many data using post
to my webservice? 我的问题是,为什么我仍然不能使用
post
将许多数据发送到我的Web服务? I was really thinking that using post
method can help me out in sending many request to my webservice, so what's the problem with my code? 我真的在想,使用
post
方法可以帮助我将许多请求发送到Web服务,那么我的代码有什么问题?
EDIT I change my code into this
编辑我将代码更改为此
$.ajax({
type: 'POST',
data: dataJSON,
url: 'processjson2.php?',
dataType: primeSettings.ajaxDataType,
success: function(data) {}
})
and my output url is this http://localhost/jQueryStudy/RamagalHTML/processjson2.php?path=update/tallyHdr
, which give me an error Session ID not found
. 而我的输出网址是
http://localhost/jQueryStudy/RamagalHTML/processjson2.php?path=update/tallyHdr
,这给了我一个Session ID not found
的错误Session ID not found
。 I found out that my datajson was not sent to my url webservice datajson was not there. 我发现我的datajson没有发送到我的网址webservice datajson不存在。
Your problem is in this line of code: 您的问题在以下代码行中:
url: 'processjson2.php?' + $.param({path:'update/tallyHdr',json:JSON.stringify(dataJSON)}),
This line appends data to the URL to which you are posting your request. 此行将数据附加到您要向其发布请求的URL。 If you have too much data, the URL will overwhelm the web server.
如果数据过多,URL将使Web服务器不堪重负。 (Basically, you are still performing a GET request.)
(基本上,您仍在执行GET请求。)
Instead, replace that line with the following. 而是用以下内容替换该行。
url: 'processjson2.php',
Then add path:'update/tallyHdr'
to your dataJSON object, and see if that works. 然后将
path:'update/tallyHdr'
到您的dataJSON对象,看看是否可行。
I have now my answer. 我现在有我的答案。 Cheeken is correct when she/he said that this line:
当她/他说这句话时,Cheeken是正确的 :
url: 'processjson2.php?' + $.param({path:'update/tallyHdr',json:JSON.stringify(dataJSON)}),
is the problem and that I am performing a get
request. 是问题,我正在执行
get
请求。 And that I should replace it with this: 我应该用它代替它:
url: 'processjson2.php?',
So, where should I put my dataJSON? 因此,我应该将dataJSON放在哪里? Here's my running code that I used:
这是我使用的运行代码:
$.ajax({
type: 'POST',
data: $.param({json:(JSON.stringify(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');
}
}
});
This line $.param({json:(JSON.stringify(dataJSON))})
converts my dataJSON into a query string, while json is the variable that holds my json data. 这行
$.param({json:(JSON.stringify(dataJSON))})
将我的dataJSON转换为查询字符串,而json是保存我的json数据的变量。 That's all that change I nade to run my program code with ajax 这就是我要用ajax运行程序代码的所有更改
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.