Home > Web Front-end > JS Tutorial > Ajax callback data assignment to js object example sharing

Ajax callback data assignment to js object example sharing

小云云
Release: 2018-02-28 11:35:58
Original
1532 people have browsed it

This article mainly shares with you examples of assigning ajax callback data to js objects. I hope it can help everyone.

  1. Suppose there is a js object as follows

var series= [{
          type: 'pie',
          name: 'Browser share',
          data: [{name: 'Chrome',y: 12.8},    {name:'IE',y: 8}]
}];
Copy after login

2. The following is the ajax method, the returned data is a json, and assign it to The data attribute of the series object

$.ajax({
url:"<%=basePath%>highchartsData.action,
async: false, //改为同步方式,避免异步方式未等ajax响应就继续向下执行
type: "POST",
success: function (data) {
              series[0].data = data;
},
dataType:"json"
});
Copy after login

3. Since the series object is also a json array, use the subscript series[0].data to assign a value to the data attribute of the first brace of the array.

The above is the detailed content of Ajax callback data assignment to js object example sharing. 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