如何解决Dropzone js将变量从php页面返回到js
我一直试图将变量从我的PHP页面返回到我的客户页面。 但是我得到这个错误 SyntaxError:JSON位置36上的意外令牌{。 也许很容易想到,我是web-dev的新手,所以我希望找到一些答案:)
我在php页面中的返回行是:
echo json_encode($urls);
我很确定这是不对的,但是我所发现的全部。
图像添加页面客户端
new Dropzone("div#myDrop",{
maxFiles: 1,uploadMultiple :false,maxFilesize: 10,url: "ajax/imagAdd.php",acceptedFiles: 'image/png,image/jpeg',success: function(file,response,url){
$(".result").html(url);
$("#working").html('image uploaded');
$("#working").show();
// or
}
});
imageAdd.php
if(isset($_FILES['file'])){
$img=$_FILES['file'];
$conn=$database->openConnection();
$filename = $img['tmp_name'];
$client_id="************";//Your Client ID here
$handle = fopen($filename,"r");
$data = fread($handle,filesize($filename));
$pvars = array('image' => base64_encode($data));
$curl = curl_init();
curl_setopt($curl,CURLOPT_URL,'https://api.imgur.com/3/image.json');
curl_setopt($curl,CURLOPT_HTTPHEADER,array('Authorization: Client-ID ' . $client_id));
curl_setopt($curl,CURLOPT_POST,1);
curl_setopt($curl,CURLOPT_RETURNTRANSFER,CURLOPT_POSTFIELDS,$pvars);
$out = curl_exec($curl);
curl_close ($curl);
$pms = json_decode($out,true);
$url=$pms['data']['link'];
if($url!=""){
$urls=$url;
// return line
echo json_encode($urls);
}else{
returnJSON(array('tp' => 'error','t' => 'wrong','m' => 'Unkown Error','b' => true));
}
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。