在Jquery AJAX中显示PHP数据 [英] Display PHP data in Jquery AJAX
问题描述
我有一个php页面,其中用单选按钮显示一些图像.首先,预先选择两张图片,然后将它们合并并显示组合.但是用户可以选择其他图像,然后单击MergeImages按钮,该按钮应显示所选的两个图像的组合.
I have a php page where I display few images with radio buttons. On start two images are pre selected and I merge those and show the combinations. But user can choose a different image and click on MergeImages button, which should display the combination of two images selected.
我在一个php文件中执行此操作,在该文件中,我通过POST将所选内容通过AJAX传递到同一文件.
I am doing this in one php file, where I pass the selected contents via POST to the same file through AJAX.
$.ajax({
url: 'CreateImage.php',
type: 'POST',
data: {imagename : newImageName},
success: function(data) {
},
error: function(jqXHR, textStatus, errorThrown) {
console.log(textStatus, errorThrown);
}
});
我获得了成功,现在我想显示数据,以便可以看到新创建的图像.我该怎么做?
I am getting a success and now I would like to display the data so that I can see the newly created images. How do I do this?
推荐答案
如果要在DIV中显示数据,可以执行以下操作:
If you want to display the data in a DIV, you can do this:
html:
<div id="myemptydiv"></div>
javascript:
javascript:
$("#myemptydiv").append(data);
php(如果您在同一个文件中,则必须清除缓冲区1st,但应将另一个php文件用于ajax请求):
php (if you are in the same file, you have to clear the buffer 1st but you should use another php file for ajax requests instead):
<?php
if(isset($_POST['imagename'])){
while(@ob_end_clean());
//do stuff here
echo $data;
exit;
}
?>
这篇关于在Jquery AJAX中显示PHP数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!