Welcome to WebmasterWorld Guest from 54.144.231.243

Forum Moderators: open

Script not updating a div as expected

   
9:05 pm on Jan 22, 2014 (gmt 0)

5+ Year Member



Hi everyone,
I'm looking for a help about one ajax script. This Ajax script is intended to get exchange rate between two currencies and show it on the browser. It's using PHP as the backend end to retrieve the current exchange rate. The div that will be refreshed has a class called 'listall'. When I look at the browser after clicking an input type button and have a look on the output using Firebug, I find that the reponse code is 200 OK and I can see the out put from Firebug but not from the div.

Here is the AJAX script:
function getTauxDeChangeOfToday(){
$.ajax({
url: 'getTodayExchangeRate.php',
type: 'POST',
dataType: 'html',
success:
function(retour){
$('.listall').html(retour);
}
});


}


The form containing the div has POST as the sending method.
can someone point me what i have done wrong for the script not to work. PLZ assume the PHP has no error as I tested it before.

Thanks
5:27 pm on Jan 23, 2014 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member



Script looks fine. You just need to check 2 things:
1. That your javascript function is actually being called
2. That the file is successfully being executed. (You have what is known as a relative path to the file in your code sample, so there is some possibility that the browser is failing to find the file.)

The simple way of testing this is with a few alerts:

function getTauxDeChangeOfToday(){
alert('Function called');
$.ajax({
url: 'getTodayExchangeRate.php',
type: 'POST',
dataType: 'html',
success: function(retour){
alert('File successfully executed');
$('.listall').html(retour);
},
error: function() {
alert('Script failed');
}
});
}
7:39 am on Jan 27, 2014 (gmt 0)

5+ Year Member



Thanks Readie, I found what I was missing: In the $(document).ready() function the first line was $('.listall').remove(); So when trying to update the div with $('.listall').html(retour) that div was absent and that's why the return from the PHP functionn was missing.

Thanks again
7:40 am on Jan 27, 2014 (gmt 0)

5+ Year Member



Thanks Readie, I found what I was missing: In the $(document).ready() function the first line was $('.listall').remove(); So when trying to update the div with $('.listall').html(retour) that div was absent and that's why the return from the PHP functionn was missing.

Thanks again
7:40 am on Jan 27, 2014 (gmt 0)

5+ Year Member



Thanks Readie, I found what I was missing: In the $(document).ready() function the first line was $('.listall').remove(); So when trying to update the div with $('.listall').html(retour) that div was absent and that's why the return from the PHP functionn was missing.

Thanks again
 

Featured Threads

Hot Threads This Week

Hot Threads This Month