Reputation: 1034
I'm quite new to jquery ajax and I'm trying to figure out how can I render the response data what I get back from php as json to update a specified div. So practically I'm having the following issue.
The JavaScript:
<script type="text/javascript">
$(document).ready(function() {
$(".ajax_call").change(function() {
var domain = document.domain;
var count = $('.ajax_call :selected').val();
var $parent = $(this).closest(".product_box");
var modul_title = $("h4", $parent).text();
$.ajax({
url:'index/ajax',
data:{mod_title:modul_title, domain:domain, count:count},
cache:'false',
datatype:'json',
success: function(response) {
if (response.status = modul_title) {
$parent.fadeOut();
$parents.(response).fadeIn();
} else {
alert("Oops, script is a no go");
}
}
});
});
});
And the HTML:
<div class="product_box">
<h4><!-- php code generating --> header</h1>
<div class="product">
<div class="thumbnail-item">
<a href=""></a>
<!-- and couple of other divs what are rendering my output in my mvc view -->
<div class="ajax_bar">
<!-- and here comes the dropdown what is triggering an ajax call -->
<select class="ajax_call" size="1" name="blala">
<option value='50'>add more 50</option>
<option value='100'>add more 100</option>
<option value='150'>add more 150</option>
</select>
</div>
</div>
</div>
</div>
What I want is to update the number of presented items with an ajax call. What is not clear to me how to render the response. Do I have to form the raw data again I mean as my html-php code looks or it can be done in another way?
Upvotes: 1
Views: 3510
Reputation: 4764
Suppose you want to generate userdefined html then can use microtemplating MicroTemplating
Hope this is what you want.
Upvotes: 1
Reputation: 176906
you need to user html or text method for this to dispaly
$parents.html(response).fadeIn();
or
$parents.text(response).fadeIn();
instead of $parents.(response).fadeIn();
Upvotes: 0
Reputation: 87073
$parents.(response).fadeIn();
should be
$parents.html(response).fadeIn();
or
$parents.text(response).fadeIn();
.html() update the content of $parents
read about .text()
Upvotes: 0