This article mainly shares with you examples of assigning ajax callback data to js objects. I hope it can help everyone.
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!