• 44
Votes
name

A PHP Error was encountered

Severity: Notice

Message: Undefined index: userid

Filename: views/question.php

Line Number: 191

Backtrace:

File: /var/www/html/cnasolution/site/application/views/question.php
Line: 191
Function: _error_handler

File: /var/www/html/cnasolution/site/application/controllers/Questions.php
Line: 419
Function: view

File: /var/www/html/cnasolution/site/index.php
Line: 315
Function: require_once

I have a strange situation where the following Click-Handler (via one() to prevent double-clicks) has a called Ajax method from the inside. The first thing it's supposed to do is to disable my button.

Normally, if I don't have any Ajax inside and just have a simple click handler, this works and disables the button immediately:

 $('#button').one('click', function (event) {     $(this).prop('disabled', true);  });     

But if I have the following, with a called sub-method which involves Ajax, I notice that the 1st statement (Disable Button) does not occur until the sub-method is complete. But why? The button should get disabled immeditely as the first statement, regardless of how long the Ajax takes to complete.

 $('#submitButton').one('click', function (event) {     $(this).prop('disabled', true); // Doesn't get disabled until AFTER submitSurvey()     submitSurvey();  // Call some method that does Ajax  });        function submitSurvey() {      $.ajax({             url: 'surveyProcess',             type: 'post',             processData: false,             contentType: false,             data: formData,             async:   false,  /* Note async = false, so nothing asynchronous here either */             success: function() {                    //...      } 

What could be going on here? I just need to disable the button immediately, without any delay.

Download script demo [LINK]
Download script demo [LINK 2] Download script demo [LINK 2]

You can use beforeSend() event for the same use

$('#submitButton').on('click', function (event) {     $.ajax({         url: 'surveyProcess',         type: 'post',         processData: false,         contentType: false,         data: formData,         async:   false,  /* Note async = false, so nothing asynchronous here either */         beforeSend: function(){             $(this).prop('disabled', true);         },         success: function() {                //...           }     });  }); 
see demo
  • 1
Reply Report