0

I read different articles on PHP and JS differences.

Code I have:

<html>


<div id"response"> GETTING ALL CONTENT HERE</div>
</html>

<script>
jQuery(function($) { // DOM is now ready

    <!-- CHANGING COLOR OF FIELD -->
    $('.metal').hover(function(){
        $main_text = $(this).text();
        $(this).text("Pievienot grozam");
    },function(){
        $(this).text($main_text);
    });

    <!-- AJAX CALL -->
        $.ajax({
            url: "/modules/mod_shop/response.php",
            type: "POST",
            async: true,
            cache: false,
            data: ({dataList: dataList}),
            dataType: "json",
            success: function (dataList) {


                console.log(testName);

                jQuery.each(dataList, function(i, data) {
                    var testValue = 'smth..';
                    var htmlContainer = '<p>data.name</p><h1><?php echo testFunction ($testValue );?></h1>';

                    $('#response').append(htmlContainer);
                });

            }
        });
    });



});
</script>

One is server side, other on client-side. I'm asking on how to make this work? An alternative options here.

Right now, with ajax I get json objects. I can get them quite easily, but I cant get out pictures, because I use special function testFunction() which resizes pictures. Is there some way to use this php function and pass in specific parameter? Something like this:

<html>
// in html part
foreach (run through all data){
   <img src="<?php echo testFunction($url) ?>"></img>
}
</html>

Is there a way to just load all pictures using php (somewhere) and then, when I do ajax call, automatically pass these pictures? (As PHP runs first and only then JS)? How would I do this? Any ideas/suggestions are welcome!

  • 1
    What are you actually trying to do? – TurtleTread Apr 18 '17 at 20:55
  • If you want to resize pictures 'on the go', like, whenever you want on a client, then you shouldn't use PHP. There are many jQuery implementations for that. However, if you want to do this once, you could also keep a resized version of an image alongside the image itself, and then just pass the resized version to the client. Finally, if you truly need to pass raw image data to the DOM using AJAX, maybe this can help: http://stackoverflow.com/questions/20035615/using-raw-image-data-from-ajax-request-for-data-uri – lennyklb Apr 18 '17 at 21:08
  • @TurtleTread I'm basically outputing image gallery. Thing is, I've every objects data in json (text/description) and also url to picture, but the url picture is huge. I've special php function that can easily resize any picture so I usually use that, but now im confused. Before I output image info alongside php function for pictures - had no problems, but now object data is coming using ajax and not sure how to related both so it would work. – JohnCoolGuy1996 Apr 19 '17 at 04:36
  • What does this php function that you use actually do? Does it use some library to created a resized image in local directory? What exactly does it do. – TurtleTread Apr 20 '17 at 04:07

0 Answers0