I am using jQuery datatables in a dynamic PHP site. I have a page “dashboard.php” with a simple search field on it. when I submit that form the search term is set to session variable then I am sent to a page that builds a datatable using “server-side data” (php). I am trying to get the session[‘searchTerm’] to be set $(“#el_id”).val(val); in the filter box, so it will filter the results if there is a term (session var) set. I am at a loss, I have tried all I can think of. Is it possible?
Share
You can trivially embed it in the “sent to a page” location when that page is generated:
Since the session value was set in the PREVIOUS page load, it’ll be available to this new page when it’s loaded, and you can output it directly into the javascript on that page. Note that I’m passing the value through json_encode, which ensures that no matter what the content of this searchTerm is, it’ll be syntactically valid javascript. If you were going to embed the term into a hidden form field, you’d use htmlspecialchars() instead.