简体   繁体   中英

Passing array to php function using ajax call does not seem to work

I am trying to pass a js array to a php function using jquery ajax. I don't understand why the data doesn't update on the page.

this is my code: js:

$('table tr').click(function(){
        var id = $(this).attr('id');
        storeId(id); // this function creates the id.
        var selected_lp = localStorage.getItem('reportArray');
        console.log(selected_lp);

        var query = 'selected_lp=' + selected_lp;
        $.ajax({
                type: "POST",
                url: "../inc/updatelponadvdash.php",  //this is where i call the function. 
                data: { selected_lparr : selected_lp },
                cache: false,
                success: function(data) {
                    return true;
                }
            });

    });

This is what i get in the console.log(selected_lp) :

["97","96","51","48","45","50","33"]

This is the content of /inc/updatelponadvdash.php

<?php
require_once 'inc.php';

    $lploop = new User();
    $lploop->adv_lploops($_POST['selected_lparr']);
?>

this is the function

 public function adv_lploops($selected_lp){
            echo ' x '.$selected_lp. ' x '; 
}

The final step is to call the function to the frontend. I require the /inc/updatelponadvdash.php to thefrontend.

At the console I see the array updated on click. For some reason the $selected_lp var in not updating in the front end. Maybe I am not calling the function as I should?

我们需要使用Aray vaues:

print_r($array);

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