Reputation: 1436
I would like have to implement Ajax/J-Query for updating database, now after that i need to reload all content of my ctp page in cakephp without refreshing/redirecting.
Is it possible ?
Please help me out.
I tried
$.ajax({
url: 'http://localhost/projectname/Experiences/experienceadd',
type: 'POST',
data: {'companyname':companyname,'title':title,'monthstart':monthstart,'location':location,'yearstart':yearstart,'yearnextstart':yearnextstart,'monthnextstart':monthnextstart,'presentyeardata':presentyeardata,'description':description},
success: function (data) {
if(data)
{
mystr = '<div style="display: block; opacity: 1;" class="item mix book mix_all" data-year="2010"> <div class="pubmain"> <div class="pubassets"> <a href="#" class="pubcollapse"> <i class="icon-expand-alt"></i> </a> </div> <h4 class="pubtitle"> ' + companyname + '</h4> <div class="pubauthor"><strong>'+ title +'</strong>,'+ location+'</div> <div class="pubcite">'+ yearstart +' - '+ yearnextstart +' , <strong>'+ presentyeardata + '</strong> </div> </div> <div style="display: none;" class="pubdetails"> <h4>'+ description+'</h4> <div class="pubdetails"> <a class="icon_a icon_right_head" class="exp_rid" id="'+ data +'" href="javascript: void(0);"><i class="icon-trash"></i> Remove</a> <a class="icon_a icon_right_head" class="exp_eid" id="'+ data +'" href="javascript: void(0);"><i class="icon-pencil"></i> Edit</a> </div> </div></div>';
$('#pexperience_details').append(mystr);
$("#experience-box").hide( 500, function() { });
$('#add-experience').show();
$().toastmessage('showSuccessToast','your skill is successfully Saved');
}
else
{
$().toastmessage('showErrorToast', 'your skill is not successfully Saved');
}
}
});
but this one only add one content area. If my issue is solve than no need of above code. any idea.....?
Thanks
Upvotes: 1
Views: 1883
Reputation: 135
Create a whole new Controller action. For example
http://localhost/projectname/Experiences/refresh
Here you return all the content you want to be refreshed. You can call this ajax function WITHIN your current ajax function (if success/data)
Additionally you might want to deactivate the layout
$this->layout = false;
Upvotes: 1