I’m trying to write an ajax POST to send a value from one ci view to another. I’ve found lots of posts on this out there, but still haven’t been able to get it right, maybe mostly because they show how to send data from form controls whereas I want to send data from a variable. On this view (Edit) I’m catching the current url which I want to send to the next view (Gallery) onclick of a jqm basic list item.
List (on controller):
$control .= '<ul data-role="listview" data-inset="true" class="toGallery">';
$control .= '<li >';
$control .= '<a href="'. site_url() .'/mobilegallery/gallery/'.$x[0]->attributes()->indexI.'">[imgname.png]</a>';
$control .= '</li>';
$control .= '</ul>';
jQuery (on view):
$(document).bind('pageinit',function(event){
var href = $(location).attr('href');
$(".toGallery").live('tap',function(){
$.ajax({
type: "POST",
url: "/mobilegallery/gallery",
data: $('href').val(),
success: function(data){
var beforeUrl = href;
alert(beforeUrl);
}
});
});
});
On Gallery page I want to make the url a variable for later use. Do I create that variable in success as above, or do I get that value on Gallery page?
If you want to keep your
urlvariable around for later use (meaning subsequent page requests), you can simply store it as custom session data in your controller:Now it would be available in any view like this: