Ajax cross-origin access ,?? Data chaos ??.

Source: Internet
Author: User
I cannot describe clearly either. go to the code and obtain the article {code...} based on the id ...} data {code ...} retrieve all document categories {code ...} data {code ...} the preceding interface is called normally separately, and the problem occurs below. The application scenario is: when loading the editing page, call the interface to obtain...

I cannot describe it clearly either. just go to the code.

Obtain an article by id
/api/article/getOne?id=' + id
Data
{"Code": 200, "data": {"id": "17", "cateId": "2", "name": "video", "studioId ": "2", "title": "wegwg network service scope", "content ": "<p> <B> gw%3wg3wg </B> </p> <B> 3wgf </B> </p> <B> gf3wg </ b> </p> ", "createdAt": "16:18:05 "}}
Retrieve all document categories
/api/category/get
Data
{"Code": 200, "data": [{"id": "1", "name": "recommended" },{ "id": "2 ", "name": "video" },{ "id": "3", "name": "slimming" },{ "id": "4", "name ": "Privacy"}]}
The preceding interface is called normally separately, and the problem occurs below. The application scenario is: when loading the editing page, the interface is called to get data to fill the page.

Real page code
// Edit the article. when loading the page, get the edited data and fill in the page $. ajax ({url: '/api/article/getOne? Id = '+ id, // obtain the information of an article type: 'GET', dataType: 'json', beforeSend: function () {$ (' # show_load '). show () ;}, success: function (article) {console. log (article); if (article. code! = 200) return false; $ ('# title '). val (article. data. title); // article title const content = htmlspecialchars_decode (article. data. content); $ ('# summernote '). summernote ('code', content); // The content of the article $. ajax ({url: '/api/category/get', // Obtain all types: 'GET', Ype: 'json', beforeSend: function () {$ ('# show_load '). show () ;}, success: function (categorys) {console. log (categorys); // The problem occurs here. all printed IDs are if (categorys. c Ode! = 200) return false; $ ('# categoryId'). empty (); $ ('# categoryId'). append ('Select category'); Categorys. data. forEach (function (v) {if (v. id = article. data. cateId) {$ (' # categoryId '). append ('$ {V. name}')} Else {$ (' # categoryId '). append ('$ {V. name}') }}, Complete: function () {$ (' # show_load '). hide () ;}}) ;}, complete: function () {$ ('# show_load '). hide ();}});
The printed data is as follows: all category IDs are changed to "1. The original document Category id is indeed "1 ". But here all are changed to 1. what is the problem?

{"Code": 200, "data": [{"id": "1", "name": "recommended" },{ "id": "1 ", "name": "video" },{ "id": "1", "name": "slimming" },{ "id": "1", "name ": "Privacy"}]}

Previously, writing like this can work normally. But today I don't know why it turns out to be like this. Lost, ^ $ ^.

Reply content:

I cannot describe it clearly either. just go to the code.

Obtain an article by id
/api/article/getOne?id=' + id
Data
{"Code": 200, "data": {"id": "17", "cateId": "2", "name": "video", "studioId ": "2", "title": "wegwg network service scope", "content ": "<p> <B> gw%3wg3wg </B> </p> <B> 3wgf </B> </p> <B> gf3wg </ b> </p> ", "createdAt": "16:18:05 "}}
Retrieve all document categories
/api/category/get
Data
{"Code": 200, "data": [{"id": "1", "name": "recommended" },{ "id": "2 ", "name": "video" },{ "id": "3", "name": "slimming" },{ "id": "4", "name ": "Privacy"}]}
The preceding interface is called normally separately, and the problem occurs below. The application scenario is: when loading the editing page, the interface is called to get data to fill the page.

Real page code
// Edit the article. when loading the page, get the edited data and fill in the page $. ajax ({url: '/api/article/getOne? Id = '+ id, // obtain the information of an article type: 'GET', dataType: 'json', beforeSend: function () {$ (' # show_load '). show () ;}, success: function (article) {console. log (article); if (article. code! = 200) return false; $ ('# title '). val (article. data. title); // article title const content = htmlspecialchars_decode (article. data. content); $ ('# summernote '). summernote ('code', content); // The content of the article $. ajax ({url: '/api/category/get', // Obtain all types: 'GET', Ype: 'json', beforeSend: function () {$ ('# show_load '). show () ;}, success: function (categorys) {console. log (categorys); // The problem occurs here. all printed IDs are if (categorys. c Ode! = 200) return false; $ ('# categoryId'). empty (); $ ('# categoryId'). append ('Select category'); Categorys. data. forEach (function (v) {if (v. id = article. data. cateId) {$ (' # categoryId '). append ('$ {V. name}')} Else {$ (' # categoryId '). append ('$ {V. name}') }}, Complete: function () {$ (' # show_load '). hide () ;}}) ;}, complete: function () {$ ('# show_load '). hide ();}});
The printed data is as follows: all category IDs are changed to "1. The original document Category id is indeed "1 ". But here all are changed to 1. what is the problem?

{"Code": 200, "data": [{"id": "1", "name": "recommended" },{ "id": "1 ", "name": "video" },{ "id": "1", "name": "slimming" },{ "id": "1", "name ": "Privacy"}]}

Previously, writing like this can work normally. But today I don't know why it turns out to be like this. Lost, ^ $ ^.

/Api/category/get to get the link of all categories, and you can confirm it again (try to directly put this link in the browser to see if the output content has id 1, I think it is generally 1, and this problem can basically be considered as an error in the background code for retrieving classification ...)

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.