Bogdan C
Bogdan C

Reputation: 399

ajax innerHTML result doesn`t return html code from PHP

ajax:

$.ajax({
type: "POST",
url: "calculator/panouri-simple/calcul-panouri-simple.php",
data:  $("#formular_comanda").serialize(),
success: function(result) 
{
     document.getElementById("show_panels").innerHTML = result;
},
error: function(result)
{
     console.log("Eroare:");
     console.log(result);
}
});

HTML:

<div id="show_panels"></div>

when I look into "View page source" on browser, there is no html code between <div id="show_panels"> and </div>.

result from ajax is returning some inputs and I call those inputs with another ajax, but in html page source, those inputs are not there.

They are visually in browser, but the html code is not present in source code. I hope you understand what do I mean here. Look at the photos.

I am calling those inputs names in a php file and I get undefined variabile .... This is my problem. Visually, the inputs are there but no html code.

enter image description here enter image description here

Debugger:

enter image description here

Upvotes: 1

Views: 603

Answers (1)

Tanner Babcock
Tanner Babcock

Reputation: 3360

Can I ask why you're using the traditional JavaScript document.getElementById when you've loaded jQuery and are using the syntax for it? You use a jQuery selector $("#formular_comanda").serialize() when you send the data to .ajax. Why not do something like...

success: function(result) {
    $("#show_panels").html(result);
},

Is your PHP file calculator/panouri-simple/calcul-panouri-simple.php expecting any GET parameters? Or anything in the POST that isn't being sent? Does the error appear in the console (you wrote with console.log), since the thing didn't go through?

Is your jQuery snippet, where you call the .ajax statement, inside of an event handler like

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

or is it just in the source as it is?

Upvotes: 1

Related Questions