使用XMLHTTPRequest对象在服务器和客户端之间传输数据,处理JSON -JAVASCRIPT
使用XMLHTTPRequest对象在服务器和客户端之间传输数据,处理JSON文件并与JavaScript中的对象一起工作
问题1: 编写一个java-script程序(在名为targil1q1.html的文件中),该程序请求get请求 使用PHP程序(targil1q1.php(,发送到它)的xmlhttprequest对象 客户端(附加到名为MOCK_DATA.JSON的作业的数据文件,其顶部看起来像这样:
[
{
"id":1,
"first_name":"Florina",
"last_name":"Head",
"email":"[email protected]",
"gender":"Female",
"ip_address":"193.117.115.240"
},
{
"id":2,
"first_name":"Lusa",
"last_name":"Ayling",
"email":"[email protected]",
"gender":"Female",
"ip_address":"247.233.187.26"
},
…
]
HTML程序将使用简单的人ID编号表单询问用户。另外, JavaScript程序将将其收到的JSON转换为JS对象,并将其打印在中心 该文档作为包含标题的表以及用户输入标识号的人的详细信息 他的。该表应按照以下示例显示,该示例显示列标题和行 其中1个人的细节 图像表
奖励问题: 回答问题后,用户可以回答另一个问题 )将显示的而不是上一个问题(并回答。该程序将保留一些成功的问题) 用户在游戏结束时回答并通知她(假设4个问题后(关于她回答的一些问题) 正确的。 代码图像
需要两个代码文件
mock_data.json
[
{
"id":1,
"first_name":"Florina",
"last_name":"Head",
"email":"[email protected]",
"gender":"Female",
"ip_address":"193.117.115.240"
},
{"id":2,"first_name":"Lusa","last_name":"Ayling","email":"[email protected]","gender":"Female","ip_address":"247.233.187.26"},
{"id":3,"first_name":"Marguerite","last_name":"Peirson","email":"[email protected]","gender":"Female","ip_address":"241.171.45.22"},
{"id":4,"first_name":"Rebeka","last_name":"Brabbs","email":"[email protected]","gender":"Female","ip_address":"44.228.21.181"},
{"id":5,"first_name":"Ode","last_name":"Leeder","email":"[email protected]","gender":"Male","ip_address":"203.181.82.15"},
{"id":6,"first_name":"Sly","last_name":"Breeder","email":"[email protected]","gender":"Male","ip_address":"26.91.12.31"},
{"id":7,"first_name":"Thorvald","last_name":"Bridges","email":"[email protected]","gender":"Male","ip_address":"145.127.204.252"},
{"id":8,"first_name":"Alonso","last_name":"Pitsall","email":"[email protected]","gender":"Male","ip_address":"41.27.229.172"},
{"id":9,"first_name":"Thor","last_name":"Lynde","email":"[email protected]","gender":"Male","ip_address":"130.116.61.0"},
{"id":10,"first_name":"Parrnell","last_name":"Haysman","email":"[email protected]","gender":"Male","ip_address":"214.121.248.210"},
{"id":11,"first_name":"Rainer","last_name":"Walcot","email":"[email protected]","gender":"Male","ip_address":"40.153.144.192"},
{"id":12,"first_name":"Nickola","last_name":"Staples","email":"[email protected]","gender":"Male","ip_address":"205.176.9.60"},
{"id":13,"first_name":"Langston","last_name":"Penfold","email":"[email protected]","gender":"Male","ip_address":"171.115.137.183"},
{"id":14,"first_name":"Mirella","last_name":"Bodill","email":"[email protected]","gender":"Bigender","ip_address":"79.48.191.67"},
{"id":15,"first_name":"Dunstan","last_name":"Strapp","email":"[email protected]","gender":"Male","ip_address":"232.175.141.13"},
{"id":16,"first_name":"Talbot","last_name":"Pactat","email":"[email protected]","gender":"Male","ip_address":"99.94.6.23"},
{"id":17,"first_name":"Beverly","last_name":"Howick","email":"[email protected]","gender":"Female","ip_address":"144.79.46.36"},
{"id":18,"first_name":"Aubrette","last_name":"Ansteys","email":"[email protected]","gender":"Female","ip_address":"132.195.181.226"},
{"id":19,"first_name":"Chaddie","last_name":"Kunkler","email":"[email protected]","gender":"Genderqueer","ip_address":"238.32.127.190"},
{"id":20,"first_name":"Rodrigo","last_name":"Lillie","email":"[email protected]","gender":"Male","ip_address":"21.73.42.39"}
]
quiz.jon
{
"quiz": {
"sport": {
"q1": {
"question":"Which one is correct team name in NBA?",
"options": [
"New York Bulls",
"Los Angeles Kings",
"Golden State Warriros",
"Huston Rocket"
],
"answer":"Huston Rocket"
}
},
"maths": {
"q1": {
"question":"5 + 7 = ?",
"options": [
"10",
"11",
"12",
"13"
],
"answer":"12"
},
"q2": {
"question":"12 - 8 = ?",
"options": [
"1",
"2",
"3",
"4"
],
"answer":"4"
}
}
}
}
非常感谢您的帮助,非常感谢您会帮助的人
Transfer data between server and client using XMLHttpRequest object, handle JSON files and work with objects in JavaScript
question 1 :
Write a java-script program (in a file named Targil1Q1.html), which requests a GET request
Using the XMLHttpRequest object from the PHP program (Targil1Q1.php (, send to it) next to
The client (the data file attached to the job named mock_data.json whose top looks like this:
[
{
"id":1,
"first_name":"Florina",
"last_name":"Head",
"email":"[email protected]",
"gender":"Female",
"ip_address":"193.117.115.240"
},
{
"id":2,
"first_name":"Lusa",
"last_name":"Ayling",
"email":"[email protected]",
"gender":"Female",
"ip_address":"247.233.187.26"
},
…
]
The HTML program will ask the user using a simple person ID number form. also,
The JavaScript program will convert the JSON it received to a JS object and print it in the center
The document as a table containing headings and the details of the person the user entered the identification number
His. The table should show according to the following example that shows the column headings and the row
In which the details of the person with - 1
Image table
Question 2:
Write the HTML program in a file named Targil1Q2.html (which you will ask the user to use
A simple form for a person's identification number. Write java-script code) inside Targil1Q2.html (which requests
Request a POST with parameters using the XMLHttpRequest object from the PHP program
(Targil1Q2.php (Read the data file mock_data.json. In the program request parameter
Send the person's ID.
The PHP program will read the mock_data.json file and generate the HTML code of a table that contains it
Titles and the details of the person the user entered his ID number, and will send the table
Next to the client, where the table will be printed according to the following example that shows the column headings and
The line in which the person's details with -1
Image table
Question 3:
Write a JavaScript program (in a file named Targil3Q1.html), which requests a POST request
Using the XMLHttpRequest object from the PHP program (Targil3Q1.php (, send to it) next to
The client (the data file attached to the job named quiz.json) image of him on the next page (.
The HTML program will calculate using the JavaScript program will convert the JSON it received
To the JS object.
The program through input that describes the topics of the question areas (sport, maths) will allow
The user has to choose the type of question the user will answer (math or sports).
Note that the question areas need to be taken from the object) in the present file these are the keys
"sport", "maths" (- you need to take into account that the file can contain many more domains
From those in the current file, that is, you do not know in advance what the topics are and how many there are - you
This information is extracted from the object.
The HTML program will be calculated using the JavaScript program and will generate a random number by number
The questions in the selected field to be extracted from the object. For example in math there are 2 questions.
And the program knows this from the object using the array size of the options key. how
Random book computers read on the web (really not complicated - Google search)
The question selected for the user correctly when the options of the answers will be input of
Radio buttons that allow only one correct answer. Note the key language of the question is visible
Like for example q2, which means you will have to connect the number of the question drawn with the string "q", in a jug
Obtain the appropriate key for the question in the object.
The user will select the correct answer and the program will tell him whether the answer is correct or not)
Know it from the object (answer key)
Bonus question:
Allow the user to answer another question after answering a question
) That will be displayed instead of the previous question (and answer it. The program will keep some successful questions)
The user answers and informs her at the end of the game (let's say after 4 questions (about some of which she answered)
Right.
Code Image
Two code files needed
mock_data.json
[
{
"id":1,
"first_name":"Florina",
"last_name":"Head",
"email":"[email protected]",
"gender":"Female",
"ip_address":"193.117.115.240"
},
{"id":2,"first_name":"Lusa","last_name":"Ayling","email":"[email protected]","gender":"Female","ip_address":"247.233.187.26"},
{"id":3,"first_name":"Marguerite","last_name":"Peirson","email":"[email protected]","gender":"Female","ip_address":"241.171.45.22"},
{"id":4,"first_name":"Rebeka","last_name":"Brabbs","email":"[email protected]","gender":"Female","ip_address":"44.228.21.181"},
{"id":5,"first_name":"Ode","last_name":"Leeder","email":"[email protected]","gender":"Male","ip_address":"203.181.82.15"},
{"id":6,"first_name":"Sly","last_name":"Breeder","email":"[email protected]","gender":"Male","ip_address":"26.91.12.31"},
{"id":7,"first_name":"Thorvald","last_name":"Bridges","email":"[email protected]","gender":"Male","ip_address":"145.127.204.252"},
{"id":8,"first_name":"Alonso","last_name":"Pitsall","email":"[email protected]","gender":"Male","ip_address":"41.27.229.172"},
{"id":9,"first_name":"Thor","last_name":"Lynde","email":"[email protected]","gender":"Male","ip_address":"130.116.61.0"},
{"id":10,"first_name":"Parrnell","last_name":"Haysman","email":"[email protected]","gender":"Male","ip_address":"214.121.248.210"},
{"id":11,"first_name":"Rainer","last_name":"Walcot","email":"[email protected]","gender":"Male","ip_address":"40.153.144.192"},
{"id":12,"first_name":"Nickola","last_name":"Staples","email":"[email protected]","gender":"Male","ip_address":"205.176.9.60"},
{"id":13,"first_name":"Langston","last_name":"Penfold","email":"[email protected]","gender":"Male","ip_address":"171.115.137.183"},
{"id":14,"first_name":"Mirella","last_name":"Bodill","email":"[email protected]","gender":"Bigender","ip_address":"79.48.191.67"},
{"id":15,"first_name":"Dunstan","last_name":"Strapp","email":"[email protected]","gender":"Male","ip_address":"232.175.141.13"},
{"id":16,"first_name":"Talbot","last_name":"Pactat","email":"[email protected]","gender":"Male","ip_address":"99.94.6.23"},
{"id":17,"first_name":"Beverly","last_name":"Howick","email":"[email protected]","gender":"Female","ip_address":"144.79.46.36"},
{"id":18,"first_name":"Aubrette","last_name":"Ansteys","email":"[email protected]","gender":"Female","ip_address":"132.195.181.226"},
{"id":19,"first_name":"Chaddie","last_name":"Kunkler","email":"[email protected]","gender":"Genderqueer","ip_address":"238.32.127.190"},
{"id":20,"first_name":"Rodrigo","last_name":"Lillie","email":"[email protected]","gender":"Male","ip_address":"21.73.42.39"}
]
Quiz.jon
{
"quiz": {
"sport": {
"q1": {
"question":"Which one is correct team name in NBA?",
"options": [
"New York Bulls",
"Los Angeles Kings",
"Golden State Warriros",
"Huston Rocket"
],
"answer":"Huston Rocket"
}
},
"maths": {
"q1": {
"question":"5 + 7 = ?",
"options": [
"10",
"11",
"12",
"13"
],
"answer":"12"
},
"q2": {
"question":"12 - 8 = ?",
"options": [
"1",
"2",
"3",
"4"
],
"answer":"4"
}
}
}
}
Thank you very much for the help really thank you to whoever will help
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论