I have the following function: $(function() { var userID = $('#user_id').text(); $.post('contracts.php', { 'user_id':userID }, function(data) { var markup = ''; if (data == 0) { $('#overlay').fadeIn(); $('#editbox').fadeIn(); markup = [ '<form id="sign_contractform_'+userID+'" method="post">', '<h1 id="sign_contract_form_heading">'+getDefinedLangConst("__SIGNCONTRACTHEADING",'',"sign_contract_form_heading",'')+'</h1>', '<div class="contract_text">Du må signere kontrakt før du får tilgang til siden</div>', '<label for="default_contract">Aksepter standardkontrakt</label><input type="checkbox" id="default_contract" value="1" name="default_contract">', '<input type="submit" name="submitcontract" disabled="disabled" id="submitcontract" value="'+getDefinedLangConst("__SUBMITCONTRACT",'',"submitcontract",'val')+'">', '</form>' ].join(''); $(markup).appendTo('#editbox').fadeIn(); } $('#sign_contractform_'+userID+' input[type=checkbox]').on('click', function() { $('#submitcontract').prop('disabled',false); $('#submitcontract').on('click', function() { var defaultContract = $('#default_contract').val(); $.post('contracts.php', { 'defaultcontract' : defaultContract,'user_id' : userID }, function(updatedata) { console.log(updatedata); }) }) }) }) }) Code (markup): What this does (or, at least is supposed to do, is check for a signed contract (the first $.post, and if no contract is found, and signed, display the form) - this works. However, the second $.post doesn't work, for some reason. It posts okay, but in Firebug it shows in red - like if the file wasn't there (404) or something similar - but it doesn't show anything - no error messages, nothing. Nor does it display a "return" - which one would assume it would show. The contracts.php-file has output no matter what result you're getting, so it should definitely show something. Anyone have any clue?
I think you need to move the submit out of the checkbox click function. $(function() { var userID = $('#user_id').text(); $.post('contracts.php', { 'user_id':userID }, function(data) { var markup = ''; if (data == 0) { $('#overlay').fadeIn(); $('#editbox').fadeIn(); markup = [ '<form id="sign_contractform_'+userID+'" method="post">', '<h1 id="sign_contract_form_heading">'+getDefinedLangConst("__SIGNCONTRACTHEADING",'',"sign_contract_form_heading",'')+'</h1>', '<div class="contract_text">Du må signere kontrakt før du får tilgang til siden</div>', '<label for="default_contract">Aksepter standardkontrakt</label><input type="checkbox" id="default_contract" value="1" name="default_contract">', '<input type="submit" name="submitcontract" disabled="disabled" id="submitcontract" value="'+getDefinedLangConst("__SUBMITCONTRACT",'',"submitcontract",'val')+'">', '</form>' ].join(''); $(markup).appendTo('#editbox').fadeIn(); } $('#sign_contractform_'+userID+' input[type=checkbox]').on('click', function() { $('#submitcontract').prop('disabled',false); }) $('#submitcontract').on('click', function() { var defaultContract = $('#default_contract').val(); $.post('contracts.php', { 'defaultcontract' : defaultContract,'user_id' : userID }, function(updatedata) { console.log(updatedata); }) }) }) }) Code (markup): Not tested.
No difference, whatsoever. It seems there's a problem calling the same file again, from within the $.post - or maybe I'm just doing something very weird in the receiving .php-file, that I just can't see...
And... I dunno what I did, really, but now it's working... *headdesk* Updated code: $(function() { var userID = $('#user_id').text(); if (userID != '' || userID != 0) { $.post('contracts.php', { 'user_id':userID }, function(data) { data = $.parseJSON(data); if (data.content == 'no contract signed') { var markup = ''; $('#overlay').fadeIn(); $('#editbox').fadeIn(); markup = [ '<form id="sign_contractform" method="post" action="contracts.php">', '<h1 id="sign_contract_form_heading">'+getDefinedLangConst("__SIGNCONTRACTHEADING",'',"sign_contract_form_heading",'')+'</h1>', '<div class="contract_text">Du må signere kontrakt før du får tilgang til siden</div>', '<label for="default_contract">Aksepter standardkontrakt</label><input type="checkbox" id="default_contract" value="1" name="default_contract">', '<input type="submit" name="submitcontract" disabled="disabled" id="submitcontract" value="'+getDefinedLangConst("__SUBMITCONTRACT",'',"submitcontract",'val')+'">', '</form>' ].join(''); $(markup).appendTo('#editbox').fadeIn(); $('#sign_contractform input[type=checkbox]').on('click', function() { $('#submitcontract').prop('disabled',false); }) $('#sign_contractform input[type=submit]').on('click', function(evt) { evt.preventDefault(); var userID = $('#user_id').text(); var defaultContract = $('#default_contract').val(); if (userID != '' && defaultContract == 1) { $.post('contracts.php', { 'defaultcontract' : defaultContract, 'user_id' : userID }, function(updatedata) { data = $.parseJSON(updatedata); showUpdateInfo(''+data.content+'',''+data.infotype+''); overlayHide(); }) } }) } else { // do nothing console.log('do nothing'); } }) } }) Code (markup):
Browsers can act funny when you are making changes to JavaScript files. Sometimes they just won't show anything different when you are editing a file (especially locally). The safest bet is close all browsers and clear their cache.
That is true, but I'm quite sure that was not the issue here - viewing the source code and accessing the js-files and others showed the correct information being present. I haven't really gone through the differences between the two versions of code, but I might have changed some value somewhere, added an else here, moved around a couple things there, and ended up with something that works as it should, so I'm more or less happy
Post within a post inside an if raises some Firefox security issue? Or the way Firefox processes the IF no userID and DefaultContract ==1 takes a long time depending on the dbase membership size? Could saving results of if functions to a variable and use the variable to process the logic let Firefox handle it better?