Javascript-how to transmit data from js to PHP files?

Source: Internet
Author: User
A newbie writes a game in js, records the players' scores and times, and wants to store them in the database for ranking. How can I safely pass the data to php for storage? A newbie writes a game in js, records the players' scores and times, and wants to store them in the database for ranking. How can I safely pass the data to php for storage?

Reply content:

A newbie writes a game in js, records the players' scores and times, and wants to store them in the database for ranking. How can I safely pass the data to php for storage?

Js regularly executes the request to the server, writes an ajax method, and post the score and time of the player to the server as the parameters of the ajax request for storage.

Ajax + https (for security)

In general, js has two execution environments.
1. In the browser;
2. Like nodejs, it is in a v8 engine.
In the first environment, js and php cannot directly interact with each other. They can only transmit data to php indirectly through ajax.
In the second environment, js and php are both running in their independent interpreters, and they cannot directly interact with each other. However, they can use pipelines, cache and database.

Ajax form submission

$. Ajax ()

A few days ago, I made something similar to real-time chat for my company.

  1. The main program is a. NET-written WCF Service interface that uses POST for data transmission and retrieval.

  2. The front-end page contains the p.

  3. Use js or jquery to refresh the display layer every 5 seconds and refresh the display layer p every time the text is sent.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.