Welcome Guest, Not a member yet? Register   Sign In
loading controller via jquery


My issues is with jquery and codeigniter. That's why posted here...

I've an image delete confirmation dialog box in jquery, that is below. Receiving ID of the image to be deleted in var myid. Please see the full code below!


var myid = $(this).attr("id");

   'title'  : 'Delete Confirmation',
   'message' : 'You are about to delete this item. <br />It cannot be restored at a later time! Continue?',
   'buttons' : {
    'Yes' : {
     'class' : 'blue',
     'action': function(){
// I want to call the controller here. This JS file included as a separate file.  
    'No' : {
     'class' : 'gray',
     'action': function(){
     } // Nothing to do in this case. You can as well omit the action property.


Please see the commented area in code where i need to call the controller. I tried jquery $.post() method but didn't workout. Also another problem is setting the site base_url(); inside the javascript. Any help for this really helpful.

Thanks in advance

uh.... was typing a very long comment and accidentally hit something on keyboard.... making everything disappear...

k, in short... you can pull the URL directly from the trigger elements...

<a href="&lt;?=site_url('controller/delete/'.$id);?&gt;" class="delete">Delete</a>

// JS
    var url=$(this).attr('href'); // jQuery way
    var url=ev.target.href; // Native javascript, faster

You could also define the base_url in javascript, but it's not 100% bullet proof with out some manual editting.
var base_url=wind0w.l0cation.hostname; // change 0 to o
That will give you only the hostname, so If your code is running in some folder, or with index.php, you'll have to add them manually.

Then about the action part, non AJAX wise, you may return TRUE/FALSE for Yes/No accordingly to continue the click event or stop it.

and about the $.post which you said not working... maybe it was about the URL which is not a good one, but with the above method, you'll always get a good one....

I suggest you to check what are the URL called in the Firebug/Chrome console, to see If it's a good URL or with some errors, either in PHP or JS.

grr... getting headache by typing the same stuff 2 times .-.


Thank you very much for your patience to sent such a detailed comment. My issue is resolved now..

Thanks again for you .. cheers Smile

Theme © iAndrew 2016 - Forum software by © MyBB