1

im making a form using jquery modal forms, the form has user info like Name, Last Name, etc.. im adding a new user via jquery .ajax and its working all fine, it adds the user to de db(mysql) and automatically adds it to a list of users that is being displayed, no problem at all here..

my list of users has an edit button, and when i press the button a modal submit form pops up with the info of that user. here's where my question pops, its doing it all fine, but when i click the edit button, the modal form pops and after 1 or 2 seconds the info of the user displays on the text fields,, is this actually good enough? or does it has to do it instantly? it kinda feels a little slow....

here is my ajax call for editing users:

$('body').on('click', '#listaUsuariosOK a', function (e){
    e.preventDefault();

    var accion = $($('#accion').val('editUser')).val();
    var id = $($('#id_user').val($(this).attr('href'))).val();

    $('#agregarUsuario').dialog('open');

    $.ajax({
        cache:false,
        type: "POST",
        dataType:"json",
        url: CI.base_url + 'admin/agregarUsuario',
        data: "&id=" + id + "&accion=" + accion,
        success: function(response){
                if(response.respuesta == 'error'){
                    //Display Error
                }else{
                    $('#text_nombre').val(response.nombre);
                    $('#text_apellido').val(response.apellidos);
                    $('#text_email').val(response.email);
                    $('#depto').val(response.depto);
                }
        } //Success End
    });//.ajax Ends
});//$('body') call Ends

i make a post call sending the id of the user to edit, then on my php I make the query for that id and return the data via json_encode()

How can i make the response time faster? thanks a lot in advance... (im new to ajax btw hehe)

0

2 Answers 2

2

AJAX is unlikely to be the issue here. It is most likely that your database is running slowly or your network is slow. AJAX's speed is entirely determined by how long it takes to round-trip to/from your server, and how long your server takes to process the requested action/url.

So, check to see how much load your server is under and try to improve its throughput on the operation you're performing during the AJAX post. That's the best place to look for AJAX speed improvements (as you can't really speed up the network latency...)

Sign up to request clarification or add additional context in comments.

Comments

0

How big is the database you are querying? Problem is probably server-side rather than javascript related.... try debugging your php code using http://php.net/manual/en/function.microtime.php calls, may help define where your script is slow. My guess would be it is the database connection or query.

1 Comment

its actually small db, cause im just putting dummie registers to test it, i have a link named 'users' thah when i click it, it retrieves my data of all users to a table, and thats actually very fast, the problem is when i click edit a user, it takes some time to retrieve the user data into the form... let me check that link you posted...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.