使用XMLHTTPRequest对象在服务器和客户端之间传输数据,处理JSON -JAVASCRIPT

发布于 2025-02-03 10:31:08 字数 8201 浏览 3 评论 0原文

使用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个人的细节 图像表

名为targil1q2.html的文件中的HTML程序(您将要求用户使用该程序 一个人的身份证号码的简单表格。在targil1q2.html(请求 从PHP程序中使用XMLHTTPRequest对象请求带有参数的帖子 (targil1q2.php(读取数据文件mock_data.json。在程序请求参数中 发送该人的身份证。 PHP程序将读取MOCK_DATA.JSON文件并生成包含它的表的HTML代码 标题和用户输入其ID号的人的详细信息,并将发送表格 在客户端旁边,将根据以下示例打印表,该示例显示了列标题和 以-1的详细信息的行 图像表

JavaScript程序(在名为Targil3Q1.html的文件中),请求邮政请求 使用PHP程序(targil3q1.php(,发送到它)的xmlhttprequest对象 下一页的客户端(附加到名为quiz.json的作业的数据文件)(。 HTML程序将使用JavaScript程序计算,将转换其收到的JSON 到JS对象。 通过输入的程序描述了问题区域的主题(运动,数学)将允许 用户必须选择用户回答的问题类型(数学或运动)。 请注意,问题区域需要从本文件中的对象中获取)这些是密钥 “运动”,“数学”( - 您需要考虑到文件可以包含更多域 从当前文件中的文件中,也就是说,您不知道主题是什么,还有多少个 - 您 此信息是从对象中提取的。 HTML程序将使用JavaScript程序计算,并将按数字生成随机数 从对象提取的选定字段中的问题。例如,在数学中有两个问题。 并且该程序使用选项密钥的数组大小从对象中知道这一点。如何 随机图书计算机在网上阅读(真的不复杂-Google搜索) 当答案的选项将输入的选项时,正确选择了用户的问题 无线电按钮只允许一个正确的答案。注意问题的关键语言是可见的 例如,Q2,这意味着您必须在水罐中将绘制的问题的数量连接起来 获取对象中问题的适当键。 用户将选择正确的答案,该程序将告诉他答案是否正确) 从对象(答案键)

奖励问题: 回答问题后,用户可以回答另一个问题 )将显示的而不是上一个问题(并回答。该程序将保留一些成功的问题) 用户在游戏结束时回答并通知她(假设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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文