我想从jQuery接收php中的base64图像,但我不知道如何在php中访问该值?
var tkpfu是Base64编码的图像,我将该var放在数据中,但是当我尝试在PHP中访问$ _POST ['tkpfl']时,会得到一个未定义变量thpfl的错误。
JavaScript的:
function __SVTK(){
var data = {};
data['tkpfl'] = tkpfu;
console.log(data);
$.ajax({
type: 'POST',
url: 'profil/chatk',
data: data,
cache: false,
contentType: 'application/x-www-form-urlencoded;charset=UTF-8',
processData: false
}).done(function(data){
console.log(data);
}).fail(function(jqXHR,status,errorThrown){
console.log(errorThrown);
console.log(jqXHR.responseText);
console.log(jqXHR.status);
});
}
PHP:
var_dump($_POST);
控制台日志:
Internal Server Error profil:375
{"error":{"type":"ErrorException","message":"Undefined index: tkpfl","file":"\/Applications\/MAMP\/htdocs\/tender\/app\/controllers\/UsersController.php","line":66}} profil:376
500
答案 0 :(得分:0)
找到解决方案:
function __SVTK(){
$.ajax({
type: 'POST',
url: 'profil/chatk',
data: {"tkpfl":tkp},
}).done(function(data){
console.log(data);
}).fail(function(jqXHR,status,errorThrown){
console.log(errorThrown);
console.log(jqXHR.responseText);
console.log(jqXHR.status);
});
}