Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
76
rated 0 times [  79] [ 3]  / answers: 1 / hits: 16236  / 11 Years ago, mon, march 25, 2013, 12:00:00

I'm trying to call a function called loadPage on click of an a tag and pass it a URL to replace the current content in a div called main via Ajax.



However, my code isn't replacing the content already in the main div or even making the Ajax call as far as I can see and I can't see where it's going wrong.



JavaScript:



$(document).ready(function () {
function loadPage(urlToLoad) {
$.ajax({
type: POST,
alert(urlToLoad);
url: urlToLoad,
data: dataString,
success: function (returnedData) {
$('#main').html(returnedData);
}
});
}
});


HTML:



<nav>
<ul>
<li><a onclick=loadPage('load.php'); href=javascript:void(0) class=nav><img src=news.png alt=Latest news width=81 height=61 class=navImage />Latest news</a>
</li>
</ul>
</nav>
<div id=main>
<section id=mainContent>abc</section>
</div>

More From » jquery

 Answers
139

You can simply do this using load:



function loadPage(urlToLoad) {
$('#main').load(urlToLoad, function () {
alert('Load was performed.');
});
}

[#79375] Saturday, March 23, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
juliettec

Total Points: 327
Total Questions: 127
Total Answers: 102

Location: Bangladesh
Member since Sat, Jan 23, 2021
3 Years ago
;