Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Cabbit

macrumors 68020
Original poster
Jan 30, 2006
2,128
1
Scotland
Code:
var jsonp = {
  currentScript: null,
  getJSON: function(url, data, callback) {
    var src = url + (url.indexOf("?")+1 ? "&" : "?");
    var head = document.getElementsByTagName("head")[0];
    var newScript = document.createElement("script");
    var params = [];
    var param_name = ""

    this.success = callback;

    data["callback"] = "jsonp.success";
    for(param_name in data){
      params.push(param_name + "=" + encodeURIComponent(data[param_name]));
    }
    src += params.join("&");

    newScript.type = "text/javascript";
    newScript.src = src;

    if(this.currentScript) head.removeChild(currentScript);
    head.appendChild(newScript);
  },
  success: null
};


function jsonTables(element) {
  // Vars
  this.element = element; // The id of the table

  this.url = "https://webservices.mysite.com/table";
  this.data = {
    timestamp: (+new Date()),
    iDisplayStart: iDisplayStart,
    iDisplayLength: limit,
    iColumns: 6,
    iSortingCols: 1,
    iSortCol_0: current_sort_order,
    sSortDir_0: current_sort_type,
    sSearch: filter
  };
  jsonp.getJSON(this.url, this.data, function(data) {
    this.jsonData = data;
    console.log(this.jsonData); // this one displays ok
  });

  console.log(this.jsonData); // this one is a error

  // Draws the table
  this.drawTable();

  // Makes Sortable
  this.sortable();
};


In my code here i have a problem where only the console.log in the jsonp.getJSON is returning outputting the data to my console, the one labeled "this is a error" says it is undefined.

How would i go about getting this data into this.jsonData?
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.