Welcome Guest, Not a member yet? Register   Sign In
Dynamic ajax calls
#1

(This post was last modified: 08-06-2015, 03:01 AM by Urastor.)

Hellou,

My current application uses the "normal" way of processing data (User submits a form, data is send to a controller method and Redirects if everything is ok).
But I wanted to make everything a Little more smooth, so I decided to use Ajax calls and bootstrap modals. To test everything, I just rewrote my user-panel-functionality, but it seems a Little.. hm complex doing it with Ajax calls, because for every function I Need an jQuery Event handler.

For example:

My view has a modal form, to Change the users Name (simplified), and a submit button, to save the changes, if everything goes right.
In my jQuery file I Need an Event, that triggers, if I click a button. Then it should perform an Ajax call:

Default.js
PHP Code:
$('form').submit(function() {
  var dtf = $(this).serialize();
  $.post('/admin/user/edit/'dtf, function(result) {
   if(data.error) {
     //Show some fancy Errors
   } else {
     location.reload(true);
   }
  }
}, 
'json'); 


The big Problem is, if I want to add a user, I would call '/admin/user/add' as URL and with that, i Need another click event. Also the edit method expects an id, or after deleting a user Location.reload() wouldn't work.
When I now have 30 of those methods, all over my application, it would be rather annoying to write all those submit handlers and it's not very .. dynamic.

Does anyone has some advice to make it better? And also how I could get CI values into my Ajax call, so I can use something like an id?









(don't know why there's so much whitespace, but I can't delete it...)
-.-.-.-.-.-.-.-.- Angel -.-.-.-.-.-.-.-.-
Reply


Messages In This Thread
Dynamic ajax calls - by Urastor - 08-05-2015, 09:18 AM
RE: Dynamic ajax calls - by mwhitney - 08-05-2015, 10:48 AM
RE: Dynamic ajax calls - by Urastor - 08-06-2015, 02:58 AM
RE: Dynamic ajax calls - by mwhitney - 08-06-2015, 06:24 AM
RE: Dynamic ajax calls - by Urastor - 08-06-2015, 02:14 PM



Theme © iAndrew 2016 - Forum software by © MyBB