Display PHP data in Jquery AJAX

前端 未结 3 981
萌比男神i
萌比男神i 2021-01-23 16:37

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 differen

相关标签:
3条回答
  • 2021-01-23 17:24

    You'll want to send with the ajax call the "dataType: 'image'," so the ajax call knows what to do with the returning data -- other options that I've used are dataType:'json' or 'text' or 'html', etc. http://docs.jquery.com/Specifying_the_Data_Type_for_AJAX_Requests

    actually it won't take anything but a string, so send back the image src to display. (I was thinking you wanted to return the actual image itself).

    0 讨论(0)
  • 2021-01-23 17:25

    Since you are running AJAX, which uses HTTP protocol for communication, HTTP relies on MIME type. Identify the callback by using 'image' as dataType.

    dataType:'image',
    
    0 讨论(0)
  • 2021-01-23 17:28

    If you want to display the data in a DIV, you can do this:

    html:

    <div id="myemptydiv"></div>
    

    javascript:

    $("#myemptydiv").append(data);
    

    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;
    }
    ?>
    
    0 讨论(0)
提交回复
热议问题