[英]unable to get the data from javascript to php
I was doing some table work on client side after that i need to send all the selected rows of the table to a php file for further processing. 之后,我需要在客户端进行一些表工作,我需要将表的所有选定行发送到php文件进行进一步处理。 For that i have used JSON ....the data which I am sending is as ....
为此,我使用了JSON...。我发送的数据是....
[Object { 6=true, product_Id="10", product_name="pn5", more...},
Object { 6=true, product_Id="12", product_name="pn7", more...},
Object { row_count=2}]
Now i am sending this via $.post('abc.php',data);
现在我
via $.post('abc.php',data);
.But now the problem starts that how parse this data in my php file as if i do $ret=$_REQUEST['data'];
但是,现在的问题开始了,如何解析该数据在我的php文件中,就像我做
$ret=$_REQUEST['data'];
than I get error ...so please let me know the correct way...... 比我得到的错误 ...所以请让我知道正确的方法......
My javascript code is... 我的JavaScript代码是...
var data1=obj.dataModel.data;
var json_object;
var exportExcel=new Array();
var exportExcel1=new Array();
console.log(data1);
//console.log()
for(var i = 0; i < selected_index.length; i++)
{
var rowIndex = selected_index[i].rowIndx;
json_object = data1[rowIndex];
//push the data in the array
exportExcel.push(json_object);
//console.log(json_object);
}
exportExcel.push({row_count:selected_index.length}); //APPENDING DATA!!
var myExcel = JSON.stringify(exportExcel);
console.log(exportExcel);
//console.log(JSON.parse(myExcel));
$.post('stock_low_Excel.php', function(msg){
if(msg == 1)
{
alert("send");
}
});
and my php file code is.... 和我的PHP文件代码是....
<?php
/**
* Created by PhpStorm.
*/
//getting the data.....
$data = $_REQUEST['object'];
//echo($data);
echo(1);
?>
now I want to know that how can I get the data sent by my JavaScript file in my php file....and how to parse the data which I am getting 现在,我想知道如何获取我的JavaScript文件在php文件中发送的数据...以及如何解析所获取的数据
You most likely want to wrap the json-objects(/collection) as they are send as 0={...};1={...} 您最可能希望将json-objects(/ collection)包装为0 = {......; 1 = {...}
$.post("my_php_file.php", {"stock_data":data}, function(data) {
console.log(data);
alert(data.message);
});
and then from php: 然后从php:
<?php
$in = isset($_POST['stock_data']) ? $_POST['stock_data'] : false;
if($in !== false) {
$data = json_decode($in, true);
echo json_encode(array('message' => 'success', 'data' => $data));
} else {
echo json_encode(array('message' => 'no data received'));
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.