开发者

callback function after submitting a form

I have the following form :

Is there a way to add a callback function to the form after it is submitted? Basically I am echoing the result of upload.php to an iframe an开发者_如何学Cd what I want to do is to get that information using a callback function.


You want to use Ajax to submit the post, and have the javascript catch the echo in a result and write out the HTML to the iframe.


As Gnostus says: use Ajax to submit the form, and attach a function for when the ajax has completed and has received a response... something like this (javascript)

// microsoft does their XMLHttpRequest differently, so make a different object for them.
var xmlhttp = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");
    xmlhttp.onreadystatechange = function() {
        if (xmlhttp.readyState==4 && xmlhttp.status==200) {
            // this point is reached when ajax has completed
            var output = xmlhttp.responseText;
            doWhateverFunctionYouLike(output);
    }
    xmlhttp.open("GET","http://some.url.here,true);
    xmlhttp.send();

Don't forget to get the values out of your form, do something like:

 val1 = form.getElementsByTagName("input")[0].value;
 val2 = form.getElementsByTagName("input")[1].value;

and submit them with the ajax call...

xmlhttp.open("GET", "http://some.url.here/?a=" + val1 + "&b=" + val2, true);

you get the idea.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜