I try searching about this but I just can't find any that can solve my problem. I want to produce a url like to this to send request to my webservice:
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"}
Here's my current javascript code i have right now:
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');
}
}
});
My .php code is this:
<?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
)
)
));
Ev开发者_StackOverflowrytime I run my program, the url is only this http://localhost/jQueryStudy/RamagalHTML/processjson2.php?path=update/tallyHdr
, the data was not posted which makes my request not executed. Please help me on this. I don't know how to fix my php.
If you're wanting all your data to be sent as part of the URL then you should use GET, not POST.
It's therefore possible to do away with the data property and append everything to the request URL:
$.ajax({
type: 'GET',
url: 'processjson2.php?path=update/tallyHdr&json='+dataJSON,
dataType: primeSettings.ajaxDataType,
success: function(data) {
if ('error' in data)
{
showMessage('ERROR: ' + data["error"]["msg"]);
}
else{
$('#tblTallyHdr').trigger('reloadGrid');
}
}
});
If you must use POST, then you just need to provide a variable name to go with your json:
$.ajax({
type: 'POST',
data: "json="+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');
}
}
});
For more info, see the examples towards the end of the page: http://api.jquery.com/jQuery.ajax/
精彩评论