1

How to assign javascript variable to php $_POST to get the data on same page.

i tried following

var t= timesheetId;//timesheet id is coming from js file 
$.ajax({
    type:"POST",
    data: {'variable': t},
});
4
  • 1
    You need to send it somewhere, and process it in a .php-file separately. Specify a url : "/phpfile.php", parameter too, where you then use $_POST['variable'] in a phpfile.php Commented Mar 7, 2017 at 21:34
  • If you're unsure of the basics of jQuery's AJAX functions read this. Commented Mar 7, 2017 at 21:36
  • i want to post variable on same page Commented Mar 7, 2017 at 21:38
  • Without having too much details, it seems like you might be confused with client-side and server-side programming. You should read through this StackOverflow question. Commented Mar 7, 2017 at 21:44

1 Answer 1

2

You need to add a url to that ajax request so that it sends it to wherever your php file is. right now it's not being sent anywhere

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.