Loading php pages using jquery

Uploading an external php file using jquery is actually simple. I just use the load () event.

Like this:

$("#someelement").load('somepage.php');

This is usually just fine, as long as I don't use the image manipulation functions.

Here is what I put inside somepage.php

<?php
$img = 'tmp/someimage.png';
$img = imagecreatefrompng($img);
header('Content-type: image/png');
imagepng($img);
?>

When somepage.php loads, I return the wrong code. (that I'm not sure what this will be considered)

I am sure there is a restriction on loading complex image functions, but I thought I would ask if there is a workaround.

+3
source share
2 answers

As @onteria_ noted, .load()does not apply to image data. This is for HTML.

You will need to create a tag <img />, set its attribute src=, and then add it to your element:

$('body').append($('<img id="someelement" />').attr('src', 'somepage.php'));
+3

, <img src="somepage.php" />, jQuery.

, jQuery . php, , - , - .

0

All Articles