How to solve the problem of not being able to access the $_POST value when using the $.post method
P粉043432210
P粉043432210 2023-08-15 11:51:39
0
1
445

I'm having a lot of trouble sending data from one page to another. I'm developing a movie website that displays movies on the homepage and when I click on a movie I want to access the movie details page with reviews. In fact, I want to send the movie ID to the movie-detail.php page because I want to filter the comments related to that movie in the comments section of the movie detail page. This is the movie poster in the homepage, created by using append in a js file, when I click on it:

... ...

It triggers this function:

function loadComments(movieId){ $.post("/web/action/show-comments.php", { movieId }); }

This is show-comments.php:

 

Commenter:




show-comments.php is included in the comments section div of the movie-detail.php page, but when I try to enter the page, it Always gives me undefined array key error regarding $movieId variable. The only thing I need is the movie ID. I've tried many things, using cookies and hiding input fields, but none seem to work, always giving me this error. I tried printing the $_POST array but it was empty. What did i do wrong?

P粉043432210
P粉043432210

reply all (1)
P粉764836448

Try the following methods and correct them if there are any errors. I think you are not using the $.post() function correctly because the movieId is not properly formatted as a key value pair. Please try the following methods

function loadComments(movieId) { $.post("/web/action/show-comments.php", { movieId: movieId }); }
    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!