I have file1.php that includes script.js. This java script makes AJAX call. Is there a way to make session array from file1.php available to AJAX success function?
Short answer is no, you can not make it directly available. But: you CAN make it available by including any needed data/information in your AJAX response that gets consumed by the client-side JavaScript code (i.e. your “success function”).
I already have some different data returning in ajax call. How would I tack on this other data to this?
Best way I think, and most flexible way, is to pass a single object that includes all of the needed data you need to pass. This object can in turn be made up of multiple objects that serve various purposes. Use JSON functions on server and client side as needed to send and receive the data as JSON objects and put in native php/javascript “object” format.
Make sense. What I actually did was just added couple more elements to the array I sent back to Ajax via echo json_encode($myArray);
where $myArray
is my original array with addition of few more data i needed.
This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.