Welcome Guest, Not a member yet? Register   Sign In
How do I call MVC Controller from with Javascript function
#3

[eluser]CodeIgniteMe[/eluser]
To call on CI Controller from JS without reloading the page would somewhat require an AJAX request or so.
You can use what NeoArc suggest, use jQuery because it has a cool syntax and has AJAX bundled with it.
This is a sample code for your issue.
Code:
<$cript src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></$cript>
<$script>
//save the URL path to your MVC controller
var request_url = '&lt;?php echo site_url('request'); /*requires URL Helper*/ ?&gt;';
//execute codes when HTML document is ready
$(document).ready(function(){
// holds the click event of the button with id=btn_Add
$('input#btn_Add').click(function(e){
  //save the button object for future purpose
  btnAdd = $(this);
  //prevent normal postback
  e.preventDefault();
  //create an AJAX request
  $.ajax(
   'url':request_url, //URL of the request
   'type':'post', //POST method
   'success':function(){ //execute when successful
    btnAdd.attr('disabled','true'); //disable the button
    btnAdd.val('sending ...'); //change the button text value
   }
  });
});
</$script>


Messages In This Thread
How do I call MVC Controller from with Javascript function - by El Forum - 03-28-2012, 07:14 PM



Theme © iAndrew 2016 - Forum software by © MyBB