Finally fell in the pit!!! Vue-resource and jquery are not the same Ajax

Source: Internet
Author: User

Today in the HTTP request, there is a problem, the same interface, the result is exactly the same, but jquery Ajax requests, Can be directly result.code fetch to the value, but in Vue-resource must use Result.body.code to get, this let me very is puzzled, result looked for half a day, vue-resource in processing result, will in its outer package a body layer, real packet in B Ody layer. On this basis of the problem, incredibly do not know, in this post out, to himself to mention a wake up, but also to other like me just in the beginning of the novice compatriots to mention a wake up, lest detours. Although Vue spent more than a year, the problem is really the first time, if not this time jquery and Vue together, perhaps not found ...

Vue-resource code is posted below

1 That . $http. Post (2 URL,3                     {4"Train": Train,5                     },6{Emulatejson:true}7 ). Then (8                     //Successful callback9                     function(Result) {Ten                         if(Result.body.code = = 10000){ One                             A                         } -                     } -);

This is the $ajax of jquery.

1 $.ajax (2             {3 Url:url,4DataType: ' JSON ',5Type: ' POST ',6Data: {' Train ': Train},7Successfunction(Result) {8                     if(Result.code = = 10000){9                        Ten                     } One                 } A             } -);

To the novice to see, the predecessors have neglected it ...

Finally fell in the pit!!! Vue-resource and jquery are not the same Ajax

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.