Performance Ajax

Asked

Viewed 100 times

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.

  • And don’t use async:false

  • Why not use false?

1 answer

1


The two ways are correct, the result will be the same and I believe it will not have a considerable performance difference.

I’d use the first situation just because I thought it was more organized.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.