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

Ajax callback data assignment to js object example sharing

小云云
小云云Original
2018-02-28 11:35:581527browse

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}]
}];

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"
});

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!

Statement:
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