Since, I am new to jQuery I am facing problem in parsing html data retrieved from ajax.
I have a form which is using ajax to post form data and retrieve the content back to that page by adding one div ( on the same page as that of form ) to display that data.
I want to perform some jQuery / Javascript operations on that data, but since I am not reloading the page, jQuery or javascript is not able to parse that data.
How can I force javascript or jquery to reparse the whole page without loading it.
Here is the code
html
<div class="col col-lg-9 search-data well">
<div class="no-results">
Search Results will appear here.
</div>
</div>
jQuery
$('.search-form').click(function(e)
{
console.log('same-page');
e.preventDefault();
var form_var = this.form;
var postData = $(this.form).serialize();
var formURL = $(this.form).attr("action");
$.ajax(
{
url : formURL,
type: "POST",
data : postData,
success:function(data, textStatus, jqXHR)
{
// console.log(data)
$('.search-data').empty(); // Delete all child nodes
$('.search-data').html(data);
},
error: function(jqXHR, textStatus, errorThrown)
{
$('.search-data').empty(); // Delete all child nodes
$('.search-data').html(data);
}
});
return false;
});
Thankyou
$('.search-data').empty();call is completely unnecessary. Also, if you have more than one element with thesearch-dataclass, it'll add the HTML to all of them.) If the ajax call fails, that code will fail because your error handler tries to get the value of a symbol (data) that isn't defined anywhere.