如何在ajax调用中将php数组作为post参数传递给url中的php文件
我想将一个php数组作为参数传递给ajax调用。但我最终会有一个 未捕获的语法错误:JSON.parse()处的JSON输入意外结束 这是一个使用XAMPP服务器开发的php应用程序如何在ajax调用中将php数组作为post参数传递给url中的php文件,php,json,Php,Json,我想将一个php数组作为参数传递给ajax调用。但我最终会有一个 未捕获的语法错误:JSON.parse()处的JSON输入意外结束 这是一个使用XAMPP服务器开发的php应用程序 **myfile.php** 这是我有一个视图链接的文件。单击该链接后,我需要将数组数据传递到ajax中的post文件,在那里我将在模式中显示内容。 为此,我使用了json_encode()和json.parse(),但最终出现了这个错误 <?php $arrOne = array('test_a
**myfile.php**
这是我有一个视图链接的文件。单击该链接后,我需要将数组数据传递到ajax中的post文件,在那里我将在模式中显示内容。
为此,我使用了json_encode()和json.parse(),但最终出现了这个错误
<?php
$arrOne = array('test_arg_one' => 'Arg One','test_arg_two' => 'Arg Two','test_arg_three' => 'Arg Three');
$arrTwo = array('test_arg_one' => 'Arg One','test_arg_two' => 'Arg Two','test_arg_three' => 'Arg Three');
$arrThree = array('test_arg_one' => 'Arg One','test_arg_two' => 'Arg Two','test_arg_three' => 'Arg Three');
$json_one = json_encode($arrOne);
$json_two = json_encode($arrTwo);
$json_three = json_encode($arrThree);
?>
<html>
<form >
<a href="#" class="view_data" id="<?php echo $view['id'];?>">VIEW</a>
</form>
<div id="MyModal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="true">
<div class="modal-dialog" style=" margin-top: -12%;">
<!-- Modal Content: begins -->
<div class="modal-content" style="width: 950px; margin-left: -190px;">
<div class="modal-header qutviewhead">
<h4 class="modal-title" style="text-align: center; margin-right: 305px;">Test</h4>
<!-- <button type="button" class="close qotviewclosebtn" data-dismiss="modal">×</button> -->
</div>
<!-- Modal Body -->
<div class="modal-body meadqrypopmdbody" style="height: 560px; overflow: scroll; overflow-x: hidden;">
<div class="header">
<img src="img1.jpg" style="width: 100%; height: 130px;">
</div>
<div style="display: flex; flex-wrap: wrap;">
<div style="width: 15%;">
<img src="img2.jpg" style="padding-top: 15px; width: 105px; height: 100%" align="left">
</div>
<div style="width: 85%;background: url('img3.jpg'); background-repeat: no-repeat; background-position: center; margin-top: 15px;">
<div id="div_one">
<div class="test-one">
</div>
</div>
</div>
</div>
<div style="margin-top: 15px; text-align: center;">
<p style="background: #2e3192; color: #fff; padding: 10px 10px;">Plot No.1148, West End Colony, Anna Nagar West Extension, Chennai-600 050. <br>
Ph : 044-26257357, 90421 33333. Email : abishek@senthilsafety.com, Web : www.ssspl.in
</p>
</div>
<div class="header">
<img src="img1.jpg" style="width: 100%; height: 130px;">
</div>
<div style="display: flex; flex-wrap: wrap;">
<div style="width: 15%;">
<img src="img2.jpg" style="padding-top: 15px; width: 105px; height: 100%" align="left">
</div>
<div style="width: 85%;background: url('img3.jpg'); background-repeat: no-repeat; background-position: center; margin-top: 15px;">
<div id="div_two">
<div class="test-two">
</div>
</div>
</div>
</div>
<div style="margin-top: 15px; text-align: center;">
<p style="background: #2e3192; color: #fff; padding: 10px 10px;">Plot No.1148, West End Colony, Anna Nagar West Extension, Chennai-600 050. <br>
Ph : 044-26257357, 90421 33333. Email : abishek@senthilsafety.com, Web : www.ssspl.in
</p>
</div>
<div class="header">
<img src="img1.jpg" style="width: 100%; height: 130px;">
</div>
<div style="display: flex; flex-wrap: wrap;">
<div style="width: 15%;">
<img src="img2.jpg" style="padding-top: 15px; width: 105px; height: 100%" align="left">
</div>
<div style="width: 85%;background: url('img3.jpg'); background-repeat: no-repeat; background-position: center; margin-top: 15px;">
<div id="div_three">
<div class="test-three">
</div>
</div>
</div>
</div>
<div style="margin-top: 15px; text-align: center;">
</div>
</div>
<div class="cusfooter">
<button type="button" class="btn btn-default modcanbtn" data-dismiss="modal">Cancel</button>
</div>
</div>
</div>
</div>
</html>
$('.view_data').click(function(){
var record = $(this).attr("id");
var obj = JSON.parse('<?= $json_one; ?>');
var facArg1 = obj.arg1;
var facArg2 = obj.arg2;
var facArg3 = obj.arg3;
var obj1 = JSON.parse('<?= $json_two; ?>');
var facArg11 = obj1.arg1;
var facArg21 = obj1.arg2;
var facArg31 = obj1.arg3;
var obj2 = JSON.parse('<?= $json_three; ?>');
var facArg12 = obj2.arg1;
var facArg22 = obj2.arg2;
var facArg32 = obj2.arg3;
$.ajax({
url:"testCat.php",
method:"post",
data:{'id':record,'facArg1':facArg1,'facArg2':facArg2,'facArg3':facArg3,'facArg11':facArg11,'facArg21':facArg21,'facArg31':facArg31,'facArg12':facArg12,'facArg22':facArg22,'facArg32':facArg32},
success:function(data){
var divs = data.split('------');
$(".test-one").html(divs[0]);
$(".test-two").html(divs[1]);
$(".test-three").html(divs[2]);
$("#MyModal").modal("show");
}
});
})
**testCat.php** [file in the ajax call]
试验
金奈600 050 Anna Nagar西延段西端殖民地1148号地块
Ph:044-2625735790442133333。电邮:abishek@senthilsafety.com,网址:www.ssspl.in
金奈600 050 Anna Nagar西延段西端殖民地1148号地块
Ph:044-2625735790442133333。电邮:abishek@senthilsafety.com,网址:www.ssspl.in
取消
$('.view_data')。单击(函数(){
var记录=$(this.attr(“id”);
var obj=JSON.parse(“”);
var facArg1=obj.arg1;
var facArg2=obj.arg2;
var facArg3=obj.arg3;
var obj1=JSON.parse(“”);
var facArg11=obj1.arg1;
var facArg21=obj1.arg2;
var facArg31=obj1.arg3;
var obj2=JSON.parse(“”);
var facArg12=obj2.arg1;
var facArg22=obj2.arg2;
var facArg32=obj2.arg3;
$.ajax({
url:“testCat.php”,
方法:“张贴”,
数据:{'id':记录,'facArg1':facArg1,'facArg2':facArg2,'facArg3':facArg3,'facArg11':facArg11,'facArg21':facArg21,'facArg31':facArg31,'facArg12':facArg12,'facArg22,'facArg32},
成功:功能(数据){
var divs=data.split('----');
$(“.test one”).html(divs[0]);
$(“.test two”).html(divs[1]);
$(“.test three”).html(divs[2]);
$(#MyModal”).modal(“show”);
}
});
})
**php**[ajax调用中的文件]
这将显示模式内显示的内容
if(isset($_POST['cert_id']))
{
$output_one = '<style>
.borderNone table,td,th{
border:none!important;
text-align:left !important;
padding:0px !important;
}
</style>
<div style="text-align:center;">
<section>
<table align="right">
<tr>
<th style="text-align: right;">Date: 20/09/2019</th>
</tr>
</table>
</section>
<section>
<div style="padding-top:35px;"></div>
<p><b><u>TEST FORM</u></b></p>
<p><b>SEC</b></p>
</section>
<br>
<section>
<table style="border:none;">';
$arrValues = array();
if(isset($_POST['facArg1']) && ($_POST['facArg1'] != '')){
$arrValues['arg_one'] = $_POST['facArg1'];
}
if(isset($_POST['facArg2']) && ($_POST['facArg2'] != '')){
$arrValues['arg_two'] = $_POST['facArg2'];
}
if(isset($_POST['facArg3']) && ($_POST['facArg3'] != '')){
$arrValues['arg_three'] = $_POST['facArg3'];
}
$i = 1;
foreach($arrValues as $key => $val){
$output_one .='<tr>
<td>'.$i.'.'.$key.'</td>
<td>'.$val.'</td>
</tr>';
$i++;
}
$i = count($arrValues) + 1;
foreach($pdfOne as $key => $val){
$output_one .= '<tr>
<td>'.$i.'.'.$key.'</td>
<td style="padding: 0px 0px 0px 40px !important;">'.$val.'</td>
</tr>';
$i++;
}
$output_one .= '</table>
</section></div>
<br>';
$output_two = '
<div style="text-align:center;"><section>
<table align="right">
<tr>
<th style="text-align: right;">Date: 20/09/2019</th>
</tr>
</table>
</section>
<section>
<div style="padding-top:35px;"></div>
<p><b><u>TEST 2</u></b></p>
</section>
<br>
<section>
<table style="border:none;">';
$arrValuesOne = array();
if(isset($_POST['facArg11']) && ($_POST['facArg11'] != '')){
$arrValuesOne['arg_one'] = $_POST['facArg11'];
}
if(isset($_POST['facVillage21']) && ($_POST['facVillage21'] != '')){
$arrValuesOne['arg_two'] = $_POST['facArg21'];
}
if(isset($_POST['facAdd31']) && ($_POST['facAdd31'] != '')){
$arrValuesOne['arg_three'] = $_POST['facArg31'];
}
$i = 1;
foreach($arrValuesOne as $key => $val){
$output_two .='<tr>
<td>'.$i.'.'.$key.'</td>
<td>'.$val.'</td>
</tr>';
$i++;
}
$i = count($arrValuesOne) + 1;
foreach($pdfTwo as $key => $val){
$output_two .= '<tr>
<td>'.$i.'.'.$key.'</td>
<td style="padding: 0px 0px 0px 40px !important;">'.$val.'</td>
</tr>';
$i++;
}
$output_two .= '</table>
</section></div>
<br>';
$output_three = '<style>
.borderNone table,td,th{
border:none!important;
text-align:left !important;
padding:0px !important;
}
</style>
<div style="text-align:center;"><section>
<table align="right">
<tr>
<th style="text-align: right;">Date:20/09/2019</th>
</tr>
</table>
</section>
<section>
<div style="padding-top:35px;"></div>
<p><b><u>TET</u></b></p>
</section>
<br>
<section>
<table style="border:none;">';
$arrValuesTwo = array();
if(isset($_POST['facName12']) && ($_POST['facName12'] != '')){
$arrValuesTwo['arg_one'] = $_POST['facName12'];
}
if(isset($_POST['facVillage22']) && ($_POST['facVillage22'] != '')){
$arrValuesTwo['arg_two'] = $_POST['facVillage22'];
}
if(isset($_POST['facAdd32']) && ($_POST['facAdd32'] != '')){
$arrValuesTwo['arg_three'] = $_POST['facAdd32'];
}
$i = 1;
foreach($arrValuesTwo as $key => $val){
$output_three .='<tr>
<td>'.$i.'.'.$key.'</td>
<td>'.$val.'</td>
</tr>';
$i++;
}
$i = count($arrValuesTwo) + 1;
foreach($pdfThree as $key => $val){
$output_three .= '<tr>
<td>'.$i.'.'.$key.'</td>
<td style="padding: 0px 0px 0px 40px !important;">'.$val.'</td>
</tr>';
$i++;
}
$output_three .= '</table>
</section></div>
<br>';
$output_two = '<div class="break-before"></div>'.$output_two;
$output_three = '<div class="break-before"></div>'.$output_three;
echo $output_one.'------'.$output_two.'------'.$output_three;
}
Kindly help me to solve this error.
Uncaught SyntaxError: Unexpected end of JSON input
at JSON.parse (<anonymous>)
at HTMLAnchorElement.<anonymous> (myfile.php:1093)
at HTMLAnchorElement.dispatch (jquery.3.2.1.min.js:3)
at HTMLAnchorElement.q.handle (jquery.3.2.1.min.js:3)
I want the array values to get displayed inside the modal.
if(设置($\u POST['cert\u id']))
{
$output\u one=
.borderNone表,td,th{
边界:没有!重要;
文本对齐:左!重要;
填充:0px!重要;
}
日期:2019年9月20日
测试表
秒
';
$arrValues=array();
如果(isset($_POST['facArg1'])和($_POST['facArg1']!=''){
$arrValues['arg_one']=$u POST['facArg1'];
}
如果(isset($_POST['facArg2'])和($_POST['facArg2']!=''){
$arrValues['arg_two']=$u POST['facArg2'];
}
如果(设置($_POST['facArg3'])和($_POST['facArg3']!=''){
$arrValues['arg_three']=$u POST['facArg3'];
}
$i=1;
foreach($arr值为$key=>$val){
$output_one.='
“.$i.”..$key.”
“.$val.”
';
$i++;
}
$i=计数($ARR值)+1;
foreach($pdfOne作为$key=>$val){
$output_one.='
“.$i.”..$key.”
“.$val.”
';
$i++;
}
$output_one.='
",;
$output\u two
日期:2019年9月20日
测试2
';
$arrValuesOne=array();
如果(isset($_POST['facArg11'])和($_POST['facArg11']!=''){
$arrValuesOne['arg_one']=$u POST['facArg11'];
}
如果(设置($_POST['facillage21'])和($_POST['facillage21']!=''){
$arrValuesOne['arg_two']=$u POST['facArg21'];
}
如果(设置($_POST['facad31'])和($_POST['facad31']!=''){
$arrValuesOne['arg_three']=$u POST['facArg31'];
}
$i=1;
foreach($arrValuesOne作为$key=>$val){
$output_two.='
“.$i.”..$key.”
“.$val.”
';
$i++;
}
$i=计数($arrValuesOne)+1;
foreach($pdfTwo作为$key=>$val){
$output_two.='
“.$i.”..$key.”
“.$val.”
';
$i++;
}
$output_two.='
",;
$output\u三
.borderNone表,td,th{
边界:没有!重要;
文本对齐:左!重要;
填充:0px!重要;
}
日期:2019年9月20日
春节
';
$arrValuesTwo=array();
如果(设置($_POST['facName12'])和($_POST['facName12']!=''){
$arrValuesTwo['arg_one']=$u POST['facName12'];
}
如果(设置($_POST['facillage22'])和($_POST['facillage22']!=''){
$arrValuesTwo['arg_two']=$u POST['facillage22'];
}
如果(设置($_POST['facad32'])和($_POST['facad32']!=''){
$arrValuesTwo['arg_three']=$u POST['facad32'];
}
$i=1;
foreach($arrValuesTwo作为$key=>$val){
$output_3;
“.$i.”..$key.”
“.$val.”
';
$i++;
}
$i=计数($arrValuesTwo)+1;
foreach($pdfThree作为$key=>$val){
$output_3;
“.$i.”..$key.”
“.$val.”
';
$i++;
}
$output_3;
",;
$output\u two=''.$output\u two;
$output_-three=''.$output_-three;
回显$output\u one.'----'.$output\u two。