I am trying to make an AJAX Request to my function in my controller and it works, however, it returns me the whole page which i don't want. I have tried encoding it with json
but no success i also have tried different formats in the url such as format=raw
, format=ajax
and format=json
none of them worked and both
format=raw
and format=json
gave me a 404 error.
So, what i am trying to do, is a request to a function in my controller that should return me "ok" but, instead of returning "ok", it gives me the whole HTML. I surely am missing something, i just don't know what it is. I have tried changing the URL parameter, dataType
but still same result. Plus, i have seen some examples wihout the controller name in the url parameter;
example:
url: index.php?option=com_gallery&task=submit
but it didn't work out for me nor did this:
url: index.php?option=com_gallery&controller=send&task=submit
; this is the only thing that has worked out for me: index.php?option=com_gallery&task=send.submit
.
Any clarifications about these url parameters when it comes to AJAX requests to the controller and its methods?
My ajax request:
$.ajax(
{ url: 'index.php?option=com_gallery&task=send.submit',
method: 'POST',
dataType: 'text',
success: function(data){
alert(data);
},
error:function(){
alert("error");
},
});
}
My controller send.php
defined('_EXEC') or die ('Restricted access');
class GalleryControllerSend extends JControllerForm
{
public function submit($key=null, $urlVar=null)
{
echo "ok";
}
}
What should i do to display just the "ok" in the function submit()
?
The only thing that has worked out was adding format=html
to the url parameter and adding exit();
below the echo "ok"
but i believe that's not the best way to do it.