Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
268 views
in Technique[技术] by (71.8m points)

Converting Javascript array to PHP array or passing it to a PHP file

I am working on a movie ticket booking database using Mysql and PHP.I've done the frontend part using HTML,CSS. The below code is to change the image of the selected seat.The Available seats are shown in red,the booked ones are white. When the user clicks on a red image it'll turn to black,to show that the seat has been selected.But i need the list of seats which are selected by the user,in other words, i want the name of the seats,the user have booked.All seats have a seat name associated with the image.I'm stuck at this point,the seat names are stored in "seats" array of javascript. But i need this data into php to update the same into my database.I've no knowledge on JSON,AJAX.etc. please help me resolve this. Thank you.

<script > var seats=[]; function sample(id){ document.getElementById(id).src="https://image.flaticon.com/icons/png/512/24/24868.png"; seats.push(id); alert(seats); } </script>


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

As I understand, once image for seat is clicked you are storing that in seats array & marking that image as black/selected.

Now you must have some Continue/Proceed/Book button to finalize selected seats.

Now add a onclick function to that button & in that function you need to create an ajax request to PHP

to pass seats array with Ajax refer here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...