Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8942521
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T11:32:07+00:00 2026-06-15T11:32:07+00:00

im working on an HTML5 project that uses multiple canvases, after the user finishes

  • 0

im working on an HTML5 project that uses multiple canvases,
after the user finishes drawing using the canvas i save them as images to the server.
this is what i have:

        function saveViaAJAX()
        {
      $("#dvloader").show();
       document.getElementById("search-result").innerHTML="saving first image...";

        var saveCanvasFront = document.getElementById("collage-front");
        var canvasDataFront = saveCanvasFront.toDataURL("image/png");
        var postDataFront = "canvasData="+canvasDataFront;
        var debugConsole= document.getElementById("search-result");

        var saveCanvasBack = document.getElementById("collage-back");
        var canvasDataBack = saveCanvasBack.toDataURL("image/png");
        var postDataBack = "canvasData="+canvasDataBack;

        var ajax = new XMLHttpRequest();
        ajax.open("POST",'index.php?option=com_canvas&format=raw&task=savecanvas',true);
        ajax.setRequestHeader('Content-Type', 'canvas/upload');

        var ajax2 = new XMLHttpRequest();
        ajax2.open("POST",'index.php?option=com_canvas&format=raw&task=savecanvas',true);
        ajax2.setRequestHeader('Content-Type', 'canvas/upload');    



       ajax.onreadystatechange=function()
        {
            if (ajax.readyState == 4)
                {
              document.getElementById("search-result").innerHTML="saving second image..";
            ajax2.send(postDataBack);
             }
        }

       ajax2.onreadystatechange=function()
       {
        if (ajax2.readyState == 4)
         {

        document.getElementById("search-result").innerHTML="canvases saved successfully";
        setTimeout('top.location.href="index.php"', 4000)
            $("#dvloader").hide();

         }
       }    

       ajax.send(postDataFront);
        }

im sure there is a more elegant way to achieve this. i just want to make sure both requests are successful.this is why im calling them serially, one after the other.
is this correct ?
Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T11:32:08+00:00Added an answer on June 15, 2026 at 11:32 am

    this worked for me

    // JavaScript Document
    
    function saveViaAJAX()
    {   
          if(some condition){
                  alert("false");
                  return false;
              } else {
                        if (confirm('confirm')) {
                        callAjax(); 
                        }
             } 
    
    }
    
    function callAjax(){
                document.getElementById("process").innerHTML="processing...";
                ajax0();
    }
    
    function ajax0()
    {
    
        var postData = "";
        var ajax = new XMLHttpRequest();
        ajax.open("POST",'index.php?....',true);    
        ajax.setRequestHeader('Content-Type', 'canvas/upload');
    
        ajax.onreadystatechange=function()
        {
            if (ajax.readyState == 4)
            {   
                document.getElementById("process").innerHTML="next process...";
                ajax1();
    
            }
        }       
    
        ajax.send(postData);    
    
    }
    
    function ajax1()
    {
    
        var ajax = new XMLHttpRequest();
        ajax.open("POST",'index.php?...',true);
        ajax.setRequestHeader('Content-Type', 'canvas/upload');
    
        ajax.onreadystatechange=function()
        {
            if (ajax.readyState == 4)
            {   
            if (ajax.status==403){
    
                document.getElementById("process").innerHTML="error: " + ajax.status + " retry...";
                setTimeout( ajax1(), 3000 );
    
              } else if (ajax.status==200 || window.location.href.indexOf("http")==-1 || ajax.responseText != 'failed'){
    
                document.getElementById("process").innerHTML="processing...";
                ajax2();
              } else {
                document.getElementById("process").innerHTML="error: " + ajax.status;
              }
    
            }
        }       
    
        ajax.send(postData);    
    
    }
    
    function ajax2()
    {
        var canvasData = saveCanvas.toDataURL("image/png");
        var postData = "canvasData="+canvasData;
    
        var ajax = new XMLHttpRequest();
        ajax.open("POST",'index.php?...',true);
        ajax.setRequestHeader('Content-Type', 'canvas/upload'); 
    
        ajax.onreadystatechange=function()
        {
            if (ajax.readyState == 4)
            {   
            if (ajax.status==403){
    
                document.getElementById("search-result").innerHTML="error: " + ajax.status + " retrying...";
                setTimeout( ajax2(), 3000 );
    
              } else if (ajax.status==200 || window.location.href.indexOf("http")==-1 || ajax.responseText != 'failed'){
                   document.getElementById("search-result").innerHTML="processing....";
                   ajax3();
                } else {
                   document.getElementById("search-result").innerHTML="error: " + ajax.status;
                }
    
            }
        }       
    
        ajax.send(postData);
    
    }
    
    
    
    function ajax3()
    {
    
        var postData = "";
        var ajax = new XMLHttpRequest();
        ajax.open("POST",'index.php?...',true);
        ajax.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); 
    
        ajax.onreadystatechange=function()
        {
            if (ajax.readyState == 4)
            {   
    
                 if (ajax.status==403){
    
                document.getElementById("search-result").innerHTML="error: " + ajax.status +
                " retrying...";
                setTimeout( ajax3(), 3000 );
    
                 } else if (ajax.status==200 || window.location.href.indexOf("http")==-1 || ajax.responseText != 'failed'){
                  document.getElementById("process").innerHTML="success";
                  }
                  else{
                   document.getElementById("process").innerHTML="error:" + ajax.status ;
                  }         
    
            }
        }       
    
        ajax.send(postData);
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently working on a JavaScript project that uses the HTML5 canvas as a
I'm using the HTML5 elements and in a project i'm working on and the
I'm admittedly favour DIV, but am working on a project that uses nested tables.
I am working on a project that uses XSLT to transform an HTML string
I'm working on some project that uses Dojo dijit.form.Select , that produce some really
The project that I am currently working on at the moment uses SVN for
I am working on a JSP project that uses Apache Tomcat 7. When running
I'm working in a project that uses the new ASP.NET WebAPI. My current task
I am working on a project that uses a touch-screen interface. I have a
I'm working on a project that uses jQuery modals that dynamically load their content

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.