- User clicks a button on the webpage
- javascript uses XMLHtppRequest to send the user’s choice to the server
- php searches the database & finds the data
That all works & the php currently displays the data by echo onto the browser, but I don’t want the data visible at this time.
What I can’t figure out is how to deliver the data so that javascript can then handle the display.
I did manage to do this by sending cookies, but I don’t think that is a good idea.
In some tests I could send the data embedded in javascript but that worked when the php file was loaded into the browser, but failed when the php file was called by XMLHttpRequest. I don’t know why it fails when called by XMLHttpRequest. It also requires html formatting in the php which I would rather not do.
Everything works except for preventing the echo just displaying to the user & assigning it to a js variable.
I am using Xampp, html, css, javascript, php, MariaDb (mySQL)
I have successfully implemented this with cookies, but that only worked with small data.
I tried embedding the $row data in js & html. This worked if the php script was loaded into the browser, but not if called in the background, as it is with XMLHtppRequest, I have no idea where the data was sent, it didn’t seem to reach the browser.
I have tried json_encode, but it still displays & I tried to use response.Text, but that only produced either “connection success” or null.
I don’t think the specific code that I have written is relevant, I think I am missing some key points.