Welcome Guest, Not a member yet? Register   Sign In
Using controller actions using jQuery AJAX?
#2

[eluser]TheFuzzy0ne[/eluser]
I'm not sure if I understand what you mean, but if I do, there are two methods that I would suggest.

Firstly, you can add functions to your controller which are designed specifically to deal with Ajax requests. You could prefix them with "ajax_".

Secondly, your controller can tell if the request is an Ajax request, by using the following logic.

Code:
if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) &&
    ($_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest'))
{
    // Do Ajaxy stuff
}
else
{
    // Do normal stuff
}

You could move this to a helper function, for example:
Code:
function is_ajax() {
    return (isset($_SERVER['HTTP_X_REQUESTED_WITH']) &&
    ($_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest'));
}

Then your controller can do something like:

Code:
if (is_ajax())
{
    // Do Ajaxy stuff
}
else
{
    // Do normal stuff.
}

I hope this helps, and that I haven't misunderstood your question.


Messages In This Thread
Using controller actions using jQuery AJAX? - by El Forum - 02-09-2009, 06:39 AM
Using controller actions using jQuery AJAX? - by El Forum - 02-09-2009, 06:51 AM
Using controller actions using jQuery AJAX? - by El Forum - 02-09-2009, 07:04 AM
Using controller actions using jQuery AJAX? - by El Forum - 02-09-2009, 07:08 AM
Using controller actions using jQuery AJAX? - by El Forum - 02-09-2009, 07:13 AM
Using controller actions using jQuery AJAX? - by El Forum - 02-09-2009, 07:26 AM
Using controller actions using jQuery AJAX? - by El Forum - 02-09-2009, 07:28 AM
Using controller actions using jQuery AJAX? - by El Forum - 02-09-2009, 07:32 AM
Using controller actions using jQuery AJAX? - by El Forum - 02-09-2009, 07:37 AM



Theme © iAndrew 2016 - Forum software by © MyBB