9 Replies - 2804 Views - Last Post: 16 August 2012 - 12:15 PM

#1 mshadow  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 37
  • Joined: 03-July 12

append a php page to a div

Posted 12 August 2012 - 11:38 AM

hi guys.......
i want to append a php page to a div tag....
$("ttt.php").appendTo("#chat");


this isn't working ........any ideas will be highly appreciated
Is This A Good Question/Topic? 0
  • +

Replies To: append a php page to a div

#2 Atli  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3730
  • View blog
  • Posts: 6,017
  • Joined: 08-June 10

Re: append a php page to a div

Posted 12 August 2012 - 12:35 PM

In order to append the contents of a PHP page to the current page, you need to request the contents of the PHP page from the server. That requires an AJAX call. The simplest form of that in jQuery is the get() function.
$.get("ttt.php", function(response) {
    // Opens an alert showing the PHP file contents.
    alert(response);
}); 



You can then use the append() function to add that to your element.
Was This Post Helpful? 1
  • +
  • -

#3 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3576
  • View blog
  • Posts: 10,442
  • Joined: 08-June 10

Re: append a php page to a div

Posted 13 August 2012 - 12:55 AM

load() should also work for getting the PHP page.
Was This Post Helpful? 0
  • +
  • -

#4 Atli  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3730
  • View blog
  • Posts: 6,017
  • Joined: 08-June 10

Re: append a php page to a div

Posted 13 August 2012 - 05:19 AM

But is there a way to use load() to append it's contents to an element? I couldn't spot one in the docs.
Was This Post Helpful? 0
  • +
  • -

#5 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3576
  • View blog
  • Posts: 10,442
  • Joined: 08-June 10

Re: append a php page to a div

Posted 15 August 2012 - 11:49 PM

right in the first paragraph:

Quote

This method is the simplest way to fetch data from the server. It is roughly equivalent to $.get(url, data, success) except that it is a method rather than global function and it has an implicit callback function. When a successful response is detected (i.e. when textStatus is "success" or "notmodified"), .load() sets the HTML contents of the matched element to the returned data.

Was This Post Helpful? 0
  • +
  • -

#6 mshadow  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 37
  • Joined: 03-July 12

Re: append a php page to a div

Posted 16 August 2012 - 09:12 AM

View PostDormilich, on 13 August 2012 - 12:55 AM, said:

load() should also work for getting the PHP page.

but its not appending it is reloading the whole div
Was This Post Helpful? 0
  • +
  • -

#7 Atli  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3730
  • View blog
  • Posts: 6,017
  • Joined: 08-June 10

Re: append a php page to a div

Posted 16 August 2012 - 09:16 AM

View PostDormilich, on 16 August 2012 - 06:49 AM, said:

right in the first paragraph:

Yes, but it "sets the HTML contents of the matched element to the returned data.", whereas mshadow was trying to append the returned data to the current contents of the element. If you just do $("#chat").load("ttt.php"), then what was in the #chat element before will be removed and replaced.

This post has been edited by Atli: 16 August 2012 - 09:17 AM

Was This Post Helpful? 0
  • +
  • -

#8 mshadow  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 37
  • Joined: 03-July 12

Re: append a php page to a div

Posted 16 August 2012 - 10:23 AM

View PostAtli, on 12 August 2012 - 12:35 PM, said:

In order to append the contents of a PHP page to the current page, you need to request the contents of the PHP page from the server. That requires an AJAX call. The simplest form of that in jQuery is the get() function.
$.get("ttt.php", function(response) {
    // Opens an alert showing the PHP file contents.
    alert(response);
}); 



You can then use the append() function to add that to your element.

('#ch').append(response);


is this how i can use append after that...??

This post has been edited by Atli: 16 August 2012 - 11:00 AM
Reason for edit:: Fixed the [code] tags.

Was This Post Helpful? 0
  • +
  • -

#9 Atli  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3730
  • View blog
  • Posts: 6,017
  • Joined: 08-June 10

Re: append a php page to a div

Posted 16 August 2012 - 11:02 AM

Yes. Except you forgot the $ in front of the jQuery call. And wasn't it #chat?
Was This Post Helpful? 0
  • +
  • -

#10 mshadow  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 37
  • Joined: 03-July 12

Re: append a php page to a div

Posted 16 August 2012 - 12:15 PM

View PostAtli, on 16 August 2012 - 11:02 AM, said:

Yes. Except you forgot the $ in front of the jQuery call. And wasn't it #chat?

JOY...thnx man.....worked just perfectly....
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1