3737 if ($ ipSessionData !== null ) {
3838 $ _SESSION [$ ipAddress ] = $ ipSessionData ;
3939 }
40- if (isset ($ alertMessage ) && trim (( string ) $ _SESSION [ ' alertMsg ' ]) != "" ) {
40+ if (! empty ($ alertMessage )) {
4141 $ _SESSION ['alertMsg ' ] = $ alertMessage ;
4242 }
4343}
@@ -371,27 +371,31 @@ function checkLoginAttempts() {
371371 format: "html"
372372 })
373373 .done(function(data) {
374- try {
375- // Parse the JSON response
376- const response = JSON.parse(data);
377-
378- if (response.captchaRequired) {
379- captchaflag = true;
380- $('#captcha').show();
381- getCaptcha('capChaw');
382- $("#challengeResponse").addClass("isRequired");
383- } else {
384- //$('#captcha').hide(); // Hide CAPTCHA if not required
385- $("#challengeResponse").removeClass("isRequired");
374+ // jQuery auto-parses JSON when the response header is JSON,
375+ // so support both string and object responses.
376+ let response = data;
377+ if (typeof data === "string") {
378+ try {
379+ response = JSON.parse(data);
380+ } catch (e) {
381+ console.error("Invalid JSON response:", data);
382+ return;
386383 }
384+ }
387385
388- // Handle any error message in the response
389- if (response.error) {
390- alert(response.error); // Show an error message if any
391- }
386+ if (response.captchaRequired) {
387+ captchaflag = true;
388+ $('#captcha').show();
389+ getCaptcha('capChaw');
390+ $("#challengeResponse").addClass("isRequired");
391+ } else {
392+ //$('#captcha').hide(); // Hide CAPTCHA if not required
393+ $("#challengeResponse").removeClass("isRequired");
394+ }
392395
393- } catch (e) {
394- console.error("Invalid JSON response:", data); // Log invalid JSON for debugging
396+ // Handle any error message in the response
397+ if (response.error) {
398+ alert(response.error); // Show an error message if any
395399 }
396400 })
397401 .fail(function(jqXHR, textStatus, errorThrown) {
@@ -403,4 +407,4 @@ function checkLoginAttempts() {
403407 </script>
404408</body>
405409
406- </html>
410+ </html>
0 commit comments