简体   繁体   中英

How to display a response from jQuery/ajax call in PHP

So I have the following code that someone else helped me get:

function updateEpisodeSeen() {
    var anime_id = <? php echo $anime_id; ?> ;
    var anime_list_entry_id = <? php echo $anime_list_entry_id; ?> ;

    jQuery.post("/path_to_it/my_php_file.php", {
        firstParam: anime_id,
        secondParam: anime_list_entry_id
    }, function (data) {
        //this is your response data from serv
        console.log(data);
    });
    return false;
}                       

Now the .php file that is ran, I update some information and echo two variables out.

So in the console.log(data); those two variable values are shown properly. I am just wondering how I can show these values in my actual php code? Since these values are updated on the backend, I want to show the users their updated values on the front end as well. So if I could possibly set a php variable to those responses and then echo those instead, but php code isn't ran until a page refreshes so that might not be the way to go since I want the values to update without the page refreshing.

if you want to assign the response to some PHP variable you can follow this

jQuery Ajax response variable from php

if you want assign to a html variable you can do that using Jquery

 $('#ID OF FIELD').val(data.text);

or

 $('#ID OF FIELD').html(data.text);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM