Welcome Guest, Not a member yet? Register   Sign In
Calling method function from Javascript/AJAX
#4

[eluser]nuwanda[/eluser]
Call your controller method from jQuery:

Code:
$.ajax({
    type: "POST",
    url: "/controller/method",
    data: ({parameter_name: parameter_value}),
    dataType: "html",    
    success: function (result) {
      $("#target_element").html(result);
    }
  });

The above code submits parameter_value as parameter_name to controller/method. Upon success, the target_element is filled with the ajax response.

Note the controller and method is relative to your site root.

In your controller, you would have something like:

Code:
function method(parameter_name){

  //do something with parameter_name

  echo result;

}

You need to echo the result, not return it.

Hope that helps.


Messages In This Thread
Calling method function from Javascript/AJAX - by El Forum - 11-25-2010, 03:08 PM
Calling method function from Javascript/AJAX - by El Forum - 11-25-2010, 03:11 PM
Calling method function from Javascript/AJAX - by El Forum - 11-25-2010, 04:02 PM
Calling method function from Javascript/AJAX - by El Forum - 11-25-2010, 04:18 PM
Calling method function from Javascript/AJAX - by El Forum - 11-25-2010, 04:51 PM
Calling method function from Javascript/AJAX - by El Forum - 11-25-2010, 09:20 PM
Calling method function from Javascript/AJAX - by El Forum - 11-25-2010, 10:41 PM
Calling method function from Javascript/AJAX - by El Forum - 11-26-2010, 03:35 PM
Calling method function from Javascript/AJAX - by El Forum - 11-26-2010, 08:22 PM



Theme © iAndrew 2016 - Forum software by © MyBB