This article mainly introduces the analysis of the error problem of the post method in Ajax directly returning a number starting with 0. Friends in need can refer to it
Today, I found a strange error when sending a simulated verification code on the web page. question. I used the following code to preset the button to send the verification code.
This is the Node.js server
<pre style="font-family: 宋体; font-size: 9pt; background-color: rgb(255, 255, 255);"><pre name="code" class="javascript">$(".reg_code_btn").click(function(e){ $(e.target).parent().children().first().val() $.ajax({ type:"POST", url:"validate/vcode", dataType:"json", data:{ vcode:"code" }, success:function(data){ console.log(data); alert(data); }, error:function(data){ console.log(data); alert("发生错误"); } }); });
Starting with 0
I will change the return value of the server If it is of JSON type, the above situation disappears. In summary, when we use AJAX to return data, try not to return data directly. It will be safer to use JSON data. The above is what I compiled for everyone. I hope it will be helpful to everyone in the future. Related articles:The reason why adding a random number after the ajax request address prevents browser caching
JS clears the IE browser cache Method
Solve the problem of the browser remembering ajax requests and being able to move forward and backward
The above is the detailed content of Analysis of the problem of error when the post method in Ajax directly returns a number starting with 0. For more information, please follow other related articles on the PHP Chinese website!