Manivasagan
Manivasagan

Reputation: 212

load php page page output into html div using jquery ajax

I want to render output of php page into html div.That means in php page has lot of jquery stuff.suppose i used current jquery ajax to load a php page.It missed to load jquery document ready stuff.

How can i do that?

Upvotes: 1

Views: 11919

Answers (3)

Pragnesh Chauhan
Pragnesh Chauhan

Reputation: 8476

you can use ajax observe method

cakephp ajax helper

<?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)'
    ) 
); ?>

Upvotes: 0

Hary
Hary

Reputation: 5818

Here's is the short example. 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";

 ?>

Upvotes: 0

Konza
Konza

Reputation: 2163

If you want to put the output of a php page to an html page using jquery and ajax. You may do this.

$(document).ready(function(){
    $("#div1").load("demo_test.php");
});

div1 is the div which is to be updated with the php content. This link may help you.

http://www.w3schools.com/jquery/jquery_ajax_intro.asp

Upvotes: 5

Related Questions