-2

this is a simple question and I´ve read many posts here about my problem. Everytime there is a solved problem but my problem still exists.

I will load a image source via jquery post. The page is written in php.

echo "<a href=\"#\" onClick=\"
$.post('/_test.php', {'call':'Chart_Test','ChartXml':'<xml><Name>Test</Name><Width>500</Width><Height>300</Height></xml>'}).always(function(imgdata) { $('#target').attr('src','data:image/png;base64,' + imgdata);});\" > Load Chart </a>";    

<img id=\"target\" width=\"500\" height=\"300\" src=\"\" />

The post calls the right function and gets an images/png. But with base64 or only pushing imgdata to src without success. in FireBug the headers are right and the imagesize is right. But the Preview looks like this if I use

base64:
�PNG



IHDR�,��֟tRNS���7X} IDATx���y|T��7��9g�}2��$dc�BEA
"*X�b�^����ۺ�Vm]n�V���.�M�[�v��[��^�}l)��B$$��>�d��,�dž ���9��|���̙3g��|��r��#I!$�s�$9�eI�0�
��baB���e|� %|[Bl��s-��cֺ"���j]�'dŠ/�XH���<7$�×|,+�.
 �H���A�a���c��S�>��}H~�/p���VYnֶ*����3�    !1aw�����c�n
��St��a�N�X�x$I�1V���.$I���S?�ڒ�d$a�ך�wm�NϹ�~�H����q�wdU3��p8�Fy����Ԑ�d"�H(�b���:r��3_4t]c�}�៵�~�e�+r�k^rA�I��}�^�ahhH��m�OP��r�d�z��L�lp����_�h�� ��qg��   !<�Sx
^����BB�p�����pc����>

Where is the - maybe - little mistake?

sAnS
  • 1,169
  • 1
  • 7
  • 10

1 Answers1

1

You need to send your image data as a base64 encoded string. What you pasted here isn't encoded at all!

Gung Foo
  • 13,392
  • 5
  • 31
  • 39
  • Okay...but the image is generated by the _test.php which is the result of an mtchart. I do not have the possebility to change the png - I think. If I embed the _test.php as src direktly the png is shown. But I need to send more data. This is why I want to use post with jquery. The Result should be the same. – user1957700 May 28 '13 at 07:35
  • I´ve tested it with an existing png...this works well. But how can I catch the string from the mtchart->stroke which sends a fully png with header and so on? – user1957700 May 28 '13 at 08:02
  • http://stackoverflow.com/questions/246801/how-can-you-encode-a-string-to-base64-in-javascript – Gung Foo May 28 '13 at 08:15
  • Good Link...I´ve added the jquery.base64.js and do now Encode the PNG after getting the post reurns. var imgdata64 = $.base64.encode(imgdata); $('#target').attr('src', 'data:image/png;base64,' + imgdata64) But This is not the solution. The result ois not the same like the encode by php. – user1957700 May 28 '13 at 08:33