Tuesday, 1 October 2013

On success of ajax post, how to send a POST request with JQuery .load() method

On success of ajax post, how to send a POST request with JQuery .load()
method

After a successful Ajax post, I would like the template associated with
POST in the handler to be rendered with JQuery's .load() method. The GET
request keeps getting called after a successful POST ...so the template
associated with GET is getting rendered instead of the one associate with
POST. Thanks for any hints you can give.
Javascript:
$(function() {
$(".topic_submit").click(function() {
var topic = $("#topic").val();
refresh = 'false'
$.ajax({
type: "POST",
url: "/mentorlist",
data: {'topic': topic},
success: function(dataString) {
$('#mentor_list').load('/mentorlist');
console.log('**mentor_list div updated via ajax.**');
}
});
return true;
});
});
HTML Form:
<form id="topic_search_form" name="topic_search_form" action="">
Topic: <input id ="topic" type="text" name="topic" size="60"
placeholder="Search by Keyword" />
<input type="submit" class="topic_submit" name="topic_submit"
value="Search" >

No comments:

Post a Comment