Luis Luis - 3 years ago 130
Javascript Question

Change DIV content using ajax, php and jQuery

I have a div which contains some text for the database:

<div id="summary">Here is summary of movie</div>

And list of links:

<a href="?id=1" class="movie">Name of movie</a>
<a href="?id=2" class="movie">Name of movie</a>

The process should be something like this:

  1. Click on the link

  2. Ajax using the url of the link to pass data via GET to php file / same page

  3. PHP returns string

  4. The div is changed to this string

Answer Source

function getSummary(id)

     type: "GET",
     url: 'Your URL',
     data: "id=" + id, // appears as $_GET['id'] @ your backend side
     success: function(data) {
           // data is ur summary



And add onclick event in your lists

<a onclick="getSummary('1')">View Text</a>
<div id="#summary">This text will be replaced when the onclick event (link is clicked) is triggered.</div>
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download