3

On user event async ajax call not working asynchronously. Issue may be due session. found one solution session_write_close

But how to integrate this with codeingiter. jquery ajax call not asynchronous

button1 click action1() 30seconds
button2 click action2() 5seconds

If I click on button1 first then button2 . I want action2() should not wait to finish execution of action1().

Below is sample code

function action1(){
 $.ajax({
 url: '/action1',
 type: 'POST',
 dataType: "json",
 async: true,
 data: $( 'form[name=form1]' ).serialize(),
 success : function(result) {
 console.log(result);
 },
 });
}
function action2(){
 $.ajax({
 url: '/action2',
 type: 'POST',
 dataType: "json",
 async: true,
 data: $( 'form[name=form2]' ).serialize(),
 success : function(result) {
 console.log(result);
 },
 });
}
asked Aug 21, 2015 at 5:08
6
  • AJAX calls are Asynchronous by default, meaning the calls are fired and rest of the code continues its execution. Your button 2 click should work just fine. Why should it wait for first AJAX call at all? Commented Aug 21, 2015 at 5:15
  • are you sure that the action2 is waiting for action1 to get completed?. I dont think so Commented Aug 21, 2015 at 5:16
  • Yes, onload this works fine. on user event works synchronously. Commented Aug 21, 2015 at 5:23
  • Maybe your server running in one thread? Commented Aug 21, 2015 at 6:12
  • log beforesend event, I'm sure you will see it fire. Commented Aug 21, 2015 at 6:20

1 Answer 1

2

It works async as expected. You can check it in chrome or firefox console in network tab. The reason of slow response can be on the server side of your app.

answered Aug 21, 2015 at 6:15
Sign up to request clarification or add additional context in comments.

1 Comment

I observed it is due to session and solution added in question. but not getting where to call session_write_close(); in action . If I call it in constructor then not able to save any session data.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.