in reply to Re: CGI Header Breaks on Second AJAX Call
in thread CGI Header Breaks on Second AJAX Call
I did not want to leave the thread dead, and I wanted to make sure I got back to everyone here.
I did heed your advice and used cURL to break this down as much as I could. I also tried to cut down the process to a minimal reproducible call. The results were even more perplexing to me.
my $json = JSON->new->utf8->encode($data); my $q = $self->query; print $q->header( -type => 'application/json', -charset => 'utf-8', ); print $json; $self->session->flush if $self->can('session') && $self->session_l +oaded; # Absolutely murder the rest of the call stack exit; # OR die if mod_perl yells at exit()
The code above intercepts my return, spits out exactly what I want, and nukes Perl immediately to prevent any unwanted data manipulation.
The browser then received that JSON as a return object (I checked the network call), and then Chrome or perhaps js wrapped the whole darn thing in HTML as some default behavior Also note the url then redirects/points to my raw Api.pm file path, not my original url login path
<html> <head><meta name="color-scheme" content="light dark"><meta charset="ut +f-8"></head> <body> <pre>Content-Type: application/json {"abbr":"Btest","companyid":7,"email":"bjp@example.com","_resume":"nul +l","name":"Brandon Test","success":1,"userid":1234}{ "error" : "API Error. ModPerl::Util::exit: (120000) exit was called + at /var/www/html/testapp/TestTracker/Api.pm line 1005", "event_threadid" : 21169609 } </pre> <div class="json-formatter-container"></div></body></html>
This is kind of why I'm here and why it has been so hard to ask for help. I don't even know what TO ask or how to break this behavior down more. CGI is a beast I have yet to tame, and something is not happy with this second AJAX call on the same page.
Oh, and for sanities sake, here's my current AJAX call as of now from debugging it a bit. Note the receiving logic in Perl has no issues interpreting this call and using the JSON data sent.
$('#twofactor_form').on('submit', function(event) { var formData = $('#twofactor_form').serialize(); event.preventDefault(); $.ajax({ url: 'api/userLogin', method: 'POST', data: JSON.stringify(formData), dataType: 'json', beforeSend: null, error: function(event) { alert(event.responseJSON.error); //debugger; }, success: function(data) { //Note this never gets tripped ever. //It never reaches the success or failure state, it just spi +ts out that raw html and my url points to the api.pm path. if ( data._resume ) { //console.log("2FA _resume hit"); var resume = JSON.parse(data._resume); window.location.replace(resume.url); } else { //console.log("2FA no-resume hit"); window.location.replace(BASE_URL); } } }); return false; });
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^3: CGI Header Breaks on Second AJAX Call
by Corion (Patriarch) on Apr 14, 2025 at 14:06 UTC | |
by brandon8696 (Initiate) on Apr 15, 2025 at 21:00 UTC |