Home > front end >  Rookie inquired, the great god to solve!
Rookie inquired, the great god to solve!

Time:09-27

Do a simple test system, now need to use ajax determine whether to submit the answer and the correct answer is consistent, the same word can continue to the next topic, it is not the same silently, and prevent click one button operation, ask how to do it, not really,,,

CodePudding user response:

refer to the original poster w - aaang response:
doing a simple test system, now need to use ajax to determine whether to submit the answer and the correct answer is consistent, the same word can continue to the next topic, it is not the same silently, and prevent click one button operation, ask how to do, really not,,,

Front end with ajax to send the answer to submit the json, back-end receives and judgment are consistent with the correct answer, and returns the results, the front-end receiving results, according to the results for different response

CodePudding user response:

Request callback, return to the success, according to the return value judgment operation again, this is the most basic things, such as
$. Ajax ({
Type: 'get',
. ,
Success: the function (res) {
If (res) code==200) {
Jump to the next topic
} else {
Alert (" wrong ")
}
}
})

CodePudding user response:



If it is a judgment, request the background directly transfer the user to enter the answers with the current topic is OK - & gt;

<meta charset="utf-8" & gt;
<meta HTTP - equiv="Content ws-security - Policy" Content="upgrade - the insecure - requests" & gt;
<meta name="viewport"
The content="width=device - width, initial - scale=1, minimum - scale=1, maximum - scale=1, the user - scalable=no"/& gt;

<style>
- cloak [v] {
Display: none
}
</style>
<body>
Question:

{{item. Question}}

Enter the answer:



<script SRC="https://cdn.bootcss.com/vue/2.6.11/vue.js" & gt; </script>
<script SRC="https://cdn.bootcss.com/vue/2.6.11/vue.min.js" & gt; </script>
<script SRC="https://cdn.bootcss.com/jquery/1.8.3/jquery.js" & gt; </script>

New Vue ({
El: '# app,
Data: {
Answer: "11111",
The list:
{
"Id" : "1101",
"Question" : "simulation data can use mock?" ,
"Answer" : "must be"
}
]

},
Mounted () {
The console. The log (1111=& gt; "" , enclosing a list);
},
Methods: {
Next () {
The console. The log (" get the user input data====& gt;" , this answer);
//statement since the data is only virtual data here, so the front circulation judgment can temporarily
/* * if the backend interface, the answer to the user directly to the input as a parameter to * */
For (var. I in this list) {
If (this. The list [I]. Answer==this. Answer) {
Alert (" correct answer ");
} else {
Alert (" wrong answer ");
}
}

}
}
})
</script>



  •  Tags:  
  • Ajax
  • Related