Question

How is possible to bring data from server onload data from server? I have something like this, and it's not working:
JS:

function getItems(){
  var formData = new FormData();
  formData.append("ask", "MainView");
  $.ajax({
    type: "POST",
    url: "getItems.php",
    data: formData,
    cache: false,
    contentType: false,
    processData: false,
    success: function(result){
      var result=trim(result);
      $("#PageWrap").html(result);
    }
  });
}
function getItemsOnLoad(){
  var formData = new FormData();
  formData.append("ask", "OnLoad");
  $.ajax({
    type: "POST",
    url: "getItemsOnload.php",
    data: formData,
    cache: false,
    contentType: false,
    processData: false,
    success: function(result){
      var result=trim(result);
      $("#onloadInfoID").html(result);
    }
  });  
}

PHP getItems.php:

echo <table onload="getItemsOnLoad()"><tr>some info</tr></table>;
Was it helpful?

Solution 2

function getItems(){
  var formData = new FormData();
  formData.append("menuItem", menuItem);
  formData.append("ask", "MainView");

  $.ajax({
    type: "POST",
    url: "getItems.php",
    data: formData,
    cache: false,
    contentType: false,
    processData: false,
    success: function(result){
      var result=trim(result);
      $("#PageWrap").html(result);
    }
  }).done(function() {
    formData.append("ask", "OnLoad");
    $.ajax({
      type: "POST",
      url: "getItemsOnload.php",
      data: formData,
      cache: false,
      contentType: false,
      processData: false,
      success: function(result){
        var result=trim(result);
        $("#onloadInfoID").html(result);
      }
    })
  });
}

That was it, .done(). Change only js file.

OTHER TIPS

If you're using jQuery, why you can't make it in ready?

$(document).ready(function() {
    getItemsOnLoad();
});

try this on <body> tag

<body onload="getItemsOnLoad()">
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top