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},
});
Pabs123
  • 3,385
  • 13
  • 29
  • 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` – Qirel Mar 07 '17 at 21:34
  • If you're unsure of the basics of jQuery's AJAX functions [read this](http://jayblanchard.net/basics_of_jquery_ajax.html). – Jay Blanchard Mar 07 '17 at 21:36
  • i want to post variable on same page – Mrunali Dighe Mar 07 '17 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**](http://stackoverflow.com/questions/13840429/what-is-the-difference-between-client-side-and-server-side-programming) question. – Qirel Mar 07 '17 at 21:44

1 Answers1

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

Pabs123
  • 3,385
  • 13
  • 29