[英]load php page page output into html div using jquery ajax
我想将php页面的输出呈现为html div。这意味着在php页面中有很多jquery stuff.suppose我使用当前的jquery ajax来加载一个php页面。它错过了加载jquery文件准备好的东西。
我怎样才能做到这一点?
如果你想使用jquery和ajax将php页面的输出放到html页面。 你可以这样做。
$(document).ready(function(){
$("#div1").load("demo_test.php");
});
div1是要用php内容更新的div。 这个链接可以帮到你。
这是一个简短的例子。 jQuery API Doc
HTML
<div id="content"></div>
<input type="button" id="btnLoad" value="Load" />
jQuery的
$("#btnLoad").click(function(){
$.ajax({
type: 'POST',
url: 'page1.php',
success: function(data){
if(data != null) $("#content").text(data)
}
});
});
page1.php中
<?php
echo "This is the sample data to be printed for request from AJAX";
?>
你可以使用ajax observe
方法
<?php echo $form->create( 'Post' ); ?>
<?php $titles = array( 1 => 'Tom', 2 => 'Dick', 3 => 'Harry' ); ?>
<?php echo $form->input( 'title', array( 'options' => $titles ) ) ?>
<label for="something">This checkbox will be send (and it will trigger Ajax reqest) </label>
<input id="something" type="checkbox" name='data[Post][something]' value='1' />
</form>
<?php
echo $ajax->observeForm( 'PostAddForm',
array(
'url' => array( 'action' => 'edit' ),
'complete' => 'alert(request.responseText)'
)
); ?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.