duanlei0282 2016-05-26 07:15
浏览 56

AJAX-PHP:返回错误的响应

I'm currently working on an PHP- Function, that's called via AJAX. It turns Base64- Strings into images. The Problem is, that the ajax call echoes the base64- String to the Front- End, instead of just my other output.

The image gets created on the Server, no Problem at all. But on the site, where you start this action (via an ajax- call) returns not only the

"done <br />" 

but also the whole base64- String of the image.

The AJAX Call looks like this:

jQuery(document).ready(function($) {
    $('#lii-form').submit(function() {

        data = {
            action: 'lii_map_images'
        };

        $.post(ajaxurl, data, function(response){
            $('#lii_log').html(response);
        });
        return false;
    });
});

The PHP- Function looks like this: (Everything works, except for the base64- string- output [which shouldn't output])

$imgUrl = $aduser -> getFoto();
$imgUrl = substr( $imgUrl, 0, -3 );
error_log($imgUrl); // tried it without this line, still prints

// turn String to image
$data = str_replace('data:image/jpeg;base64,', '', $base64_string);
$data = str_replace(' ', '+', $data);
$data = base64_decode($data);

$img_data = imagecreatefromstring($data);
$file = $uploaddir."/".$filename;

imagejpeg($img_data, $file);
imagedestroy($img_data);

echo "done <br />";

I'm working with Wordpress, btw.

EDIT

The output looks like this:

wtf

EDIT 2

I tried to remove the response from the ajax call:

   $.post(ajaxurl, data, function(response){
        $('#lii_log').html(response);
    });

to

   $.post(ajaxurl, data, function(response){

    });

but it still showed the image data.

EDIT 3

The Image- data seems to be more of a raw jpeg data than base64.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
    • ¥15 CSAPPattacklab
    • ¥15 一直显示正在等待HID—ISP
    • ¥15 Python turtle 画图
    • ¥15 关于大棚监测的pcb板设计
    • ¥15 stm32开发clion时遇到的编译问题
    • ¥15 lna设计 源简并电感型共源放大器
    • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
    • ¥15 Vue3地图和异步函数使用
    • ¥15 C++ yoloV5改写遇到的问题