如何将GET操作的返回推送到var

时间:2015-12-17 03:09:09

标签: javascript jquery json

我试图将GET操作的返回值推送到var。



// Get operation to get data form an API

$('#submit').on('click', function(){
             
            $.ajax({
                type : 'post',
                url: 'http://localhost/redmine/projects.json',
               
                
                contentType:'application/json',
                 
                //data:JSON.stringify($('form').serializeObject()), // post data || get data
                success : function(results){
                    console.log(msg, status, jqXHR);
                    
                    return results;
                },
                error: function(xhr, resp, text) {
                    console.log(xhr, resp, text);
                }
            })
         
 });

//want to PUSH data to generate a diagram here (vis_charts)

var nodes = new vis.DataSet([ {"id":1,"label":"issue_01"},{"id":2,"label":"issue_02"},{"id":3,"label":"issue_03"},{"id":4,"label":"issue_04"},{"id":5,"label":"issue_05"},{"id":6,"label":"issue_06"},{"id":7,"label":"issue_07"},{"id":8,"label":"issue_08"},{"id":9,"label":"issue_09"},{"id":10,"label":"issue_10"},{"id":11,"label":"issue_11"},{"id":12,"label":"issue_12"},{"id":13,"label":"issue_13"},{"id":14,"label":"issue_14"},{"id":15,"label":"issue_15"},{"id":16,"label":"issue_16"},{"id":17,"label":"issue_17"},{"id":18,"label":"issue_18"},{"id":19,"label":"issue_19"},{"id":20,"label":"issue_20"},{"id":21,"label":"issue_21"},{"id":22,"label":"issue_22"},{"id":23,"label":"issue_23"},{"id":24,"label":"issue_24"},{"id":25,"label":"issue_25"},{"id":26,"label":"issue_26"},{"id":27,"label":"issue_27"},{"id":28,"label":"issue_28"},{"id":29,"label":"issue_29"},{"id":30,"label":"issue_30"} ]);

 
  var edges = new vis.DataSet([
    {"from":1,"to":2,"arrows":"to"},{"from":1,"to":3,"arrows":"to"},{"from":2,"to":4,"arrows":"to"},{"from":2,"to":5,"arrows":"to"},{"from":3,"to":7,"arrows":"to"},{"from":3,"to":8,"arrows":"to"},{"from":3,"to":6,"arrows":"to"},{"from":4,"to":9,"arrows":"to"},{"from":4,"to":10,"arrows":"to"},{"from":5,"to":11,"arrows":"to"},{"from":6,"to":12,"arrows":"to"},{"from":7,"to":13,"arrows":"to"},{"from":7,"to":14,"arrows":"to"},{"from":8,"to":15,"arrows":"to"},{"from":9,"to":16,"arrows":"to"},{"from":10,"to":17,"arrows":"to"},{"from":10,"to":18,"arrows":"to"},{"from":11,"to":19,"arrows":"to"},{"from":12,"to":20,"arrows":"to"},{"from":13,"to":20,"arrows":"to"},{"from":14,"to":21,"arrows":"to"},{"from":15,"to":21,"arrows":"to"},{"from":16,"to":22,"arrows":"to"},{"from":17,"to":23,"arrows":"to"},{"from":18,"to":24,"arrows":"to"},{"from":19,"to":24,"arrows":"to"},{"from":20,"to":25,"arrows":"to"},{"from":21,"to":25,"arrows":"to"},{"from":22,"to":26,"arrows":"to"},{"from":23,"to":27,"arrows":"to"},{"from":24,"to":27,"arrows":"to"},{"from":25,"to":27,"arrows":"to"},{"from":25,"to":28,"arrows":"to"},{"from":26,"to":29,"arrows":"to"},{"from":27,"to":29,"arrows":"to"},{"from":28,"to":30,"arrows":"to"},{"from":29,"to":30,"arrows":"to"}
  ]);

  // create a network
  var container = document.getElementById('mynetwork');
  var data = {
    nodes: nodes,
    edges: edges
  };
  var options = {layout:{randomSeed:2}};
  var network = new vis.Network(container, data, options);

<div id="mynetwork"></div>
<button id="submit"></button>
&#13;
&#13;
&#13;

在我手动输入json对象的那一刻,我想将GET操作的返回推到下面的第X个位置,

var nodes = new vis.DataSet([ x ]);

任何人都可以指导我。

0 个答案:

没有答案