Javascript 从另一个ajax函数获取json编码数据
我使用的是prestashop 1.6,我有一个ajax函数,其中我对一些数据进行编码,我使用Javascript 从另一个ajax函数获取json编码数据,javascript,php,ajax,smarty,prestashop-1.6,Javascript,Php,Ajax,Smarty,Prestashop 1.6,我使用的是prestashop 1.6,我有一个ajax函数,其中我对一些数据进行编码,我使用echo在控制台上成功地检索到了这些数据。现在我必须在另一个ajax函数中解码这个json数据,以获得特定变量的值。对不起,我是一个1.6版的新手 我的第一个ajax函数: public function ajaxProcessAddQrVideo(){ $target_dir = _PS_IMG_DIR_.DS.'video_qr'; $id_product = Tools::ge
echo
在控制台上成功地检索到了这些数据。现在我必须在另一个ajax函数中解码这个json数据,以获得特定变量的值。对不起,我是一个1.6版的新手
我的第一个ajax函数:
public function ajaxProcessAddQrVideo(){
$target_dir = _PS_IMG_DIR_.DS.'video_qr';
$id_product = Tools::getValue('id_product');
$stamp = strtotime('now');
$filename = 'video_qr_'.$id_product.'_'.$stamp.'.jpg';
$target_file = $target_dir.DS.$filename;
$upload = $_FILES['video_qr_attachment_file'];
$err = array();
$uploaded = false;
if($upload['type'] !='image/jpeg'){
array_push($err,"Veuillez entrer un fichier JPG");
}
if(empty($err)){
$uploaded = @move_uploaded_file($upload['tmp_name'], $target_file);
$this->context->smarty->assign('uploaded', $uploaded);
$this->context->smarty->assign('filename', $filename);
}
$this->json =array(
'uploaded'=>$uploaded,
'err'=>$err,
'id_product'=>$id_product,
'stamp'=>$stamp,
'file_name'=>$filename,
);
echo json_encode($this->json);
exit;
}
我想在第二个ajax函数中获得'file_name'的值:
public function ajaxProcessAddVideo(){
$img_path = json_decode($this->json,true);
$filename = $img_path['file_name'];
$id_lang = Context::getContext()->language->id;
$script = Tools::getValue('script');
$id_product = Tools::getValue('id_product');
$id_group_vid = Tools::getValue('cust_group');
//add qr_code video
$qr_code =$filename;
$err = true;
$insert = false;
$videos = array();
$vid = new MpsVideo();
$vid->id_product = $id_product;
$vid->url = $script;
$vid->cust_group = $id_group_vid;
$vid->date_add = date('Y-m-d H:i:s');
$vid->active = 1;
$vid->qrcode = $qr_code;
$is_existing = Db::getInstance()->getValue("SELECT COUNT(id_mps_video) FROM `ps_mps_video` WHERE id_product=$id_product AND url = '$script'");
if($is_existing==0){
$insert = $vid->save();
$id_group = explode(',',$id_group_vid);
$group_name = array();
foreach($id_group as $k){
$group = new Group($k);
$group_name[] = $group->name[$id_lang];
}
$vid->group_names = implode('<br/>',$group_name);
}
echo json_encode(array(
'err'=>$err,
'video_exists'=>$is_existing,
'insert'=>$insert,
'vid'=>$vid,
));
exit;
}
公共函数ajaxProcessAddVideo(){
$img\u path=json\u decode($this->json,true);
$filename=$img_路径['file_name'];
$id_lang=Context::getContext()->language->id;
$script=Tools::getValue('script');
$id_product=Tools::getValue('id_product');
$id_group_vid=Tools::getValue('cust_group');
//添加二维码视频
$qr_代码=$filename;
$err=true;
$insert=假;
$videos=array();
$vid=新的MpsVideo();
$vid->id\u product=$id\u product;
$vid->url=$script;
$vid->cust\u group=$id\u group\u vid;
$vid->date_add=date('Y-m-dh:i:s');
$vid->active=1;
$vid->qrcode=$qr\u码;
$is_existing=Db::getInstance()->getValue(“从`ps_mps_video`中选择COUNT(id_mps_video),其中id_product=$id_product,url='$script');
如果($is_existing==0){
$insert=$vid->save();
$id_group=explode(“,”,$id_group_vid);
$group_name=array();
foreach($id\u组为$k){
$group=新组($k);
$group_name[]=$group->name[$id_lang];
}
$vid->group_name=内爆(“
,$group_name”);
}
echo json_编码(数组(
'err'=>$err,
'video_exists'=>$is_existing,
'insert'=>$insert,
'vid'=>$vid,
));
出口
}
我不知道如何做到这一点,但我知道这是可能的。如果有人能帮助理解这一点,我将非常感激。第一个函数的结果是json,必须从另一个文件读取该结果,然后将其传递给第二个函数。否则,同一函数应读取该json:
$data = file_get_contents("file/file_json_result.php");
$img_path = json_decode($data, true);
第一个函数的结果是json,该结果必须从另一个文件读取,然后传递给第二个函数。否则,同一函数应读取该json:
$data = file_get_contents("file/file_json_result.php");
$img_path = json_decode($data, true);
谢谢好主意我会试试的谢谢好主意我会试试的