homepage Welcome to WebmasterWorld Guest from 54.161.155.142
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

    
Script not updating a div as expected
dbarasuk




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

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

 

Readie




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

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

dbarasuk




msg:4640449
 7:39 am on Jan 27, 2014 (gmt 0)

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

dbarasuk




msg:4640450
 7:40 am on Jan 27, 2014 (gmt 0)

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

dbarasuk




msg:4640451
 7:40 am on Jan 27, 2014 (gmt 0)

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

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved