Javascript Ajax请求返回div中的HTML代码

Javascript Ajax请求返回div中的HTML代码,javascript,jquery,html,ajax,Javascript,Jquery,Html,Ajax,我希望使用ajax请求从另一个页面返回并执行html内容 第一个页面基本上只是一个请求get.php页面的页面,并在div中显示这很好,没有问题 index.php <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script> <script> function get_page(){ $.ajax({ type: 'GET',

我希望使用ajax请求从另一个页面返回并执行html内容

第一个页面基本上只是一个请求get.php页面的页面,并在div中显示这很好,没有问题

index.php

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script>
function get_page(){
   $.ajax({
   type: 'GET',
   url: '/get.php',
   dataType: 'html'
  }).done(function( data ) {
  $('#get_page').html(data);
  });
}   
get_page();
</script>



<div id='get_page'></div>

函数get_page(){
$.ajax({
键入:“GET”,
url:“/get.php”,
数据类型:“html”
}).完成(功能(数据){
$('get#u page').html(数据);
});
}   
获取页面();
第二个页面上基本上只有一个表单,我希望能够从第一个页面index.php提交表单,但是当提交表单时,没有发生任何事情,可以从get.php返回html代码并将其插入
之间,以便在浏览源代码时可以在div之间看到它,或者如何在从index.php获取.php

get.php

<form action='index.php'>
<input type='text' class='form-control' name='cu_fname' required>
<input type='text' class='form-control' name='cu_lname' required>
<input type='submit' value='Save' >
</form>


请记住,我对ajax和javascript还不太熟悉,如果可能的话,请提供一个例子作为回答。

我知道你在使用PHP,为什么不使用PHP include

<div id='get_page'>
   <?php include 'get.php';?>
</div>


抱歉,现在编辑的站点太小了。如果在
.done
功能中执行
console.log(data)
?它会将html内容加载到控制台中,但不允许提交。您可以复制粘贴到这里控制台中的内容吗?如果您想将表单提交到
get.php
,那么您的操作应该是get.php,而不是
index.php
。如果你想使用ajax,你需要点击submit按钮来处理它。我还应该提到,在HTML5中,使用iframes是不受欢迎的。我已经看过这两个选项,我希望使用ajax方法。你的ajax对我来说很好。你有任何控制台错误吗??您的ajax调用是否成功获取页面?默认方法是GET,因此我认为这不是问题所在。您应该在回答中解释一些内容,因为对您来说显而易见的内容可能对其他人来说并不明显
<iframe src="get.php">
  <p>Your browser does not support iframes.</p>
</iframe>
<form action='index.php' method='post'>
 <input type='text' class='form-control' name='cu_fname' required>
 <input type='text' class='form-control' name='cu_lname' required>
 <input type='submit' value='Save'>
</form>