1
Developing an application, and testing some calls ajax
I have come across two different situations, but in both of which I have the feedback I need.
What I want to know is, if there’s any other way, and what’s the difference between them, if any is faster, etc...
First situation
Javascript
// ajax
get_ajax(1, true);
function get_ajax(id, aguardar) {
$.ajax({
type: 'GET',
contentType: 'application/json; charset=utf-8',
async: !aguardar,
data: { id: id },
url: 'controller/get_ajax',
success: (...)
error:(...)
});
}
PHP
// controller
public function get_ajax()
{
$id = $this->input->get('id');
print_r($id);
}
Situation Second
Javascript
// ajax
get_ajax(1, true);
function get_ajax(id, aguardar) {
$.ajax({
type: 'GET',
contentType: 'application/json; charset=utf-8',
async: !aguardar,
url: 'controller/get_ajax/' + id,
success: (...)
error:(...)
});
}
PHP
// controller
public function get_ajax($id)
{
print_r($id);
}
Apparently they are equal, except the way the argument id
is being passed on.
In the primeira situação
, I’m sending the id
through data:
and retrieving in the controller through the method GET
.
In the segunda situação
, I’m sending the id
through the URL
of ajax
, and recovering through the parameter.
There is no significant difference in performance, especially when using the
jQuery
.– Valdeir Psr
And don’t use
async:false
– Leandro Angelo
Why not use false?
– Wagner Fillio