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>
当我在浏览器上查看“查看页面源代码”时,<div id="show_panels">
之间没有 html 代码。和 </div>
.
result
从 ajax 返回一些输入,我用另一个 ajax 调用这些输入,但在 html 页面源中,这些输入不存在。
它们在浏览器中可见,但源代码中不存在 html 代码。我希望你明白我在这里的意思。看看照片。
我在 php 文件中调用这些输入名称,我得到 undefined variabile ...
.这是我的问题。从视觉上看,有输入但没有 html 代码。
调试器:
最佳答案
我能问一下为什么在加载 jQuery 并使用它的语法时使用传统的 JavaScript document.getElementById
吗?当您将数据发送到 .ajax
时,您使用 jQuery 选择器 $("#formular_comanda").serialize()
。为什么不做类似...
success: function(result) {
$("#show_panels").html(result);
},
您的 PHP 文件 calculator/panouri-simple/calcul-panouri-simple.php
是否需要任何 GET 参数?或 POST 中未发送的任何内容?由于事情没有通过,错误是否出现在控制台中(您使用 console.log
编写)?
是您的 jQuery 片段,您在其中调用 .ajax
语句,在事件处理程序中,例如
$(document).ready(function() {
// ...
});
或者它只是在源代码中吗?
关于javascript - ajax innerHTML 结果不从 PHP 返回 html 代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47679354/