Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- PROBLEM :
- On FireFox : Everything running fine
- On Internet Explorer (here 10) :
- When the submit button is clicked, it fires first "onclick" function.
- Console logs :
- - button clicked
- - No Errors
- - Not generated yet
- - ajax call
- AND STAY STUCKED THERE UNTIL I CLICK ON THE BUTTON AGAIN (without page refresh, only click)!
- On 2nd click, console logs :
- - button clicked
- - no errors
- - not generated yet
- - ajax call
- - Error : [object Object] - - {"readyState":4,"responseText":"","status":500,"statusText":"Internal Server Error"}
- - called back
- - button clicked
- - no errors
- - not generated yet
- - ajax call
- - function success
- - called back
- - button clicked
- - no errors
- - generated!
- AT THAT POINT, FORM IS SUBMITTED AND EVERYTHING OK.
- WHY does it need 2 clicks on the button... why does ajax fail the first time and not second... :(
- thanks for help / reading
- */
- //JAVASCRIPT :
- $(document).ready(function(){
- generated = false;
- errors = true;
- //somewhere in the code, when all fields are filled errors become false... (not important)
- });
- $("body").on("click","#submitButton",function(event){
- console.log("button clicked");
- if(errors){
- console.log("errors somewhere");
- event.preventDefault();
- }else{
- console.log("no errors");
- if(generated == false){
- event.preventDefault();
- console.log("not generated yet");
- generatePdf(myData,function(){
- console.log("called back function");
- $("#myForm").submit();
- });
- }else{
- console.log("already generated");
- $("#myForm").submit();
- }
- }
- });
- function generatePdf(myData,callback){
- console.log("ajax call");
- $.ajax({
- type : "POST",
- url : "./myFile.php",
- data : {"myData":myData},
- dataType : "json",
- error : function(response){
- console.log("error : "+response+" - "+response.responseText+" - "+JSON.stringify(response));
- },
- success : function(response){
- console.log("function success");
- generated = true;
- callback();
- }
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement