Home Web Front-end JS Tutorial Analysis of the problem of error when the post method in Ajax directly returns a number starting with 0

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

May 22, 2018 pm 04:29 PM
ajax post return

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("发生错误"); 
    } 
  }); 
});</pre><br> 
<br> 
<pre></pre> 
<pre></pre> 
调试结果如下:</pre>
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!

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

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP Tips: Quickly Implement Return to Previous Page Function PHP Tips: Quickly Implement Return to Previous Page Function Mar 09, 2024 am 08:21 AM

PHP Tips: Quickly Implement Return to Previous Page Function

How to solve the 403 error encountered by jQuery AJAX request How to solve the 403 error encountered by jQuery AJAX request Feb 20, 2024 am 10:07 AM

How to solve the 403 error encountered by jQuery AJAX request

How to solve jQuery AJAX request 403 error How to solve jQuery AJAX request 403 error Feb 19, 2024 pm 05:55 PM

How to solve jQuery AJAX request 403 error

How to get variables from PHP method using Ajax? How to get variables from PHP method using Ajax? Mar 09, 2024 pm 05:36 PM

How to get variables from PHP method using Ajax?

What results does MySQL return after inserting data? What results does MySQL return after inserting data? Mar 01, 2024 am 10:27 AM

What results does MySQL return after inserting data?

How to solve the problem of jQuery AJAX error 403? How to solve the problem of jQuery AJAX error 403? Feb 23, 2024 pm 04:27 PM

How to solve the problem of jQuery AJAX error 403?

How to implement PHP to jump to the page and carry POST data How to implement PHP to jump to the page and carry POST data Mar 22, 2024 am 10:42 AM

How to implement PHP to jump to the page and carry POST data

PHP code example: How to use POST to pass parameters and implement page jumps PHP code example: How to use POST to pass parameters and implement page jumps Mar 07, 2024 pm 01:45 PM

PHP code example: How to use POST to pass parameters and implement page jumps

See all articles