Home > Web Front-end > JS Tutorial > body text

Analysis of the problem of error when the post method in Ajax directly returns a number starting with 0

亚连
Release: 2018-05-22 16:29:00
Original
1937 people have browsed it

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("发生错误"); 
    } 
  }); 
});


 
 
调试结果如下:
Copy after login

## If we only look at our own code part, we will not find what we should questionable. But if we find during debugging that the error return values ​​​​of returning an object object have the same commonality:

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!