Skip to content Skip to sidebar Skip to footer

Pass A Return Value From Php To Js

I have 3 files main.php, action.js and ajax.php and i successfully changed the content on click of some divs from main.php to some of ajax.php with a ajax call in my javascript fil

Solution 1:

in the success function, response, is what you get back from the PHP. so sending JSON would be easiest, because then your response is just an object.

Lets say ajax.php returns this JSON

{"newtextcaption":"whatever the text is","boxhtml":"whatever your box html is","AjaxValue":4389489473289}

then your success function should be

success: function(response) {
                $('.gridnr1, .textnr1').fadeOut(400, function(){
                    $('.textnr2, .gridnr2').fadeIn(400);
                });

                var newtextcaption = response.newtextcaption;
                var box = response.boxhtml;

                $('#textnr2').html(newtextcaption);
                $('#gridnr2').html(box);

                for (var i=0; i<response.AjaxValue; i++) {
                     DOSOMETHINGWITH i;
                }

Post a Comment for "Pass A Return Value From Php To Js"