0

I am trying to clone a div from a dynamically generated pages to another page using Ajax, and I keeping getting "null" as a result.

Here is the chain of pages: Home -> MainCat -> SubCat1 -> SubCat2 -> FinalProd

I need to clone a div from the MainCat and append it to the FinalProd page.

Here the Ajax function:

function bodyClass(div) {
   var catName = $('#location').children().eq(4).text(),
      rootPar = ('root.com/MainCat/'),
      banner = $('#divToBeCloned').clone().html();

   $.ajax({
      type: "GET",
      url: rootPar,
      dataType: 'html',
      data: {param: div},
      success: function(html){
         console.log(banner);
      }
   });

}
bodyClass();

In addition, I also get 4 of the same error:

GET chrome-extension://enhhojjnijigcajfphajepfemndkmdlo/cast_sender.js net::ERR_FAILEDOj @ www-embed-player.js:632Pj @ www-embed-player.js:633(anonymous function) @ www-embed-player.js:633Oj.c.onerror @ www-embed-player.js:631

If I console log the different variables outside the Ajax call, I get what i need in terms of the correct url and the #divToBeCloned content. What is it that I'm missing in the Ajax?

Thank you.

Sergio
  • 792
  • 3
  • 10
  • 35
  • The F-I-R-S-T(!) thing that I would do, here, is to engage your browser's debugging features. Let it *show* *you* exactly what the browser-client is sending to the server, and then, exactly what (byte for byte ...) said server is sending in return. At the same time, tell JavaScript to tell you, in the console log, EXACTLY(!) what is in those three variables that you are attempting to pass. – Mike Robinson Jun 23 '16 at 21:37
  • Mike, the console tells me just null with the code as it stands above. If I console each individual var I get what I need ie: catName = mainCat, rootPar = root.com/mainCat, banner = the complete html contained in div. Strangely enough, if I use load() function it works as i intend it to. – Sergio Jun 23 '16 at 21:49
  • provide full html page and all APIs responses – Maksym Semenykhin Jul 12 '16 at 12:44

1 Answers1

0

What if you change your AJAX call to look like this:

   $.ajax({
      type: "GET",
      url: rootPar,
      dataType: 'html',
      data: {param: div},
      success: function(html){
        console.log($('#divToBeCloned', html).html());
      }
   });

Would it do the trick?

Tony
  • 149
  • 5