0

I've function for imageResizing($p, $p2); which I use like this:

<image src="<?php echo imageResizing($url, $size); ?>"></image>

I'm using jquery ajax to fetch the data from objects and display them:

$.ajax({
            url: "..",
            type: "POST",
            async: true,
            cache: false,
            data: ({dataList: dataList}),
            dataType: "json",
            success: function (list) {

                jQuery.each(list, function(i, data) {
                    var pictureURL = data.url; // Get url like http://google.com
                    var htmlContainer = '<p> data.name</p><h1> data.lastname</h1><img src="<?php echo imageResizing(pictureURL, 300);?>"></img>';

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

            }
        });

I get correct data.name/lastname values, but when I try to use my function for picture resizing I get stuck! I understand, that PHP and JS doesn't run on the same time, also client-side/server-side fact. How can I achieve this?

Poo123
  • 49
  • 1
  • 1
  • 9
  • 1
    [Have you watched the AJAX request / response in the browser's developer tools? Have you included the jQuery library in the project? Are there any errors reported? Are you running this on a web-server?](http://jayblanchard.net/basics_of_jquery_ajax.html) – Jay Blanchard Apr 18 '17 at 12:30
  • @JayBlanchard he may not be running it on a webserver. – unixmiah Apr 18 '17 at 12:32
  • That's why I ask @unixmiah. AJAX, as you well know, requires a web-server. – Jay Blanchard Apr 18 '17 at 12:33
  • Your PHP code (`echo imageResizing(pictureURL, 300);`) runs *once* when the page loads. And likely fails with a syntax error because `pictureURL` is not a valid identifier. Whatever you're trying to accomplish, you're going to have to re-structure it. You can't run PHP code client-side in your browser. – David Apr 18 '17 at 12:36
  • you need to have php on both servers. are you on windows or a mac? if you're on windows install xampp if you on a mac, use mamp and give it another try. – unixmiah Apr 18 '17 at 12:46
  • @unixmiah I'm using WAMP and I've Windows machine. My idea is, as PHP runs first, would be to firstly run the function, so it loads all the pictures I need, and then, when JS is execuded use them. Not sure how to do this via code – Poo123 Apr 19 '17 at 05:53
  • @Poo123 if the js file has .php file extension it should run the php code in js in wamp environment – unixmiah Apr 19 '17 at 11:59

0 Answers0