Jump to content

Autosave a Form


fohanlon

Recommended Posts

Hi

 

Below is the code I am using (found after a net search - not mine).  I load init() in body on page load.:

 

function init()

{

    window.setInterval(autoSave, 20000); // 20 seconds

    }

 

 

    function autoSave()

            var status = document.getElementById("status").value;

           

            var params = "?status=" + status;

            var http = getHTTPObject();

http.onreadystatechange = function()

{

if(http.readyState == 4 && http.status == 200) // 200 = HTTP OK

{

// alert(http.responseText);

alert("All data for this current participant has been auto saved");

}

    };

            http.open("POST", "mypageaddress.php" + params, true);

http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");

http.setRequestHeader("Content-length", params.length);

http.setRequestHeader("Connection", "close");

            http.send(params);

    }

       

        //cross-browser xmlHTTP getter

        function getHTTPObject() {

            var xmlhttp;

            /*@cc_on

            @if (@_jscript_version >= 5)

                try {

                    xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");

                }

                catch (e) {                    try {

                        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");

                    }

                    catch (E) {

                        xmlhttp = false;

                    }

                }

            @else

                xmlhttp = false;

            @end @*/ 

           

            if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {

                try { 

                    xmlhttp = new XMLHttpRequest();

                } catch (e) {

                    xmlhttp = false;

                }

            }

           

            return xmlhttp;

        }

 

The page will refresh and I have a php function to update mysql tab if($_SERVER["REQUEST_METHOD"] == "POST")

{ }

 

but this is not being executed.

 

Thanks,

 

Fergal.

 

Link to comment
https://forums.phpfreaks.com/topic/208112-autosave-a-form/#findComment-1087874
Share on other sites

Try:

//Change:
window.setInterval(autoSave, 20000);   // 20 seconds
//To:
window.setInterval("autoSave()", 20000);   // 20 seconds

//Change:
var params = "?status=" + status;
//To
var params = "status="+status;

 

After all of that, open the page in firefox, and select 'Tools->Error Console'.  Watch the error console for any errors the script might throw.

Link to comment
https://forums.phpfreaks.com/topic/208112-autosave-a-form/#findComment-1087963
Share on other sites

Hi Jcbones

 

I did as you mentioned and I put a echo "<script>alert('here');</script>"; message in my php code on form submission but in FF nothing is happening.  Not even the alert I have in the function AutoSave is appearing.  really stuck on this one.  Thanks for the help.

 

Fergal.

 

Link to comment
https://forums.phpfreaks.com/topic/208112-autosave-a-form/#findComment-1088031
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.