Skip to content
Advertisement

How to pass jQuery variables to PHP

I am replacing the text of a div with a form so the user can edit it with it, but I don’t know how to pass the content of the variables from jQuery to PHP so the form can get the previous text and the id of the post.

JavaScript

EDIT:

What I need is to pass the jQuery postId and text variables into PHP, so the $edited_text and $edited_id variables will have the same information. The values that I have right now for those PHP variables are temporary so the page doesn’t call an error when displaying the code. :c

I am not trying to pass the variables to a different file, but to the “value” inside of the form that is placed with the replaceWith(); inside the jQuery.

Advertisement

Answer

Make ajax call in your javascript like this:

JavaScript

And in your php code :

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement