提交表单后的回调函数

发布于 2024-10-26 02:18:27 字数 92 浏览 4 评论 0原文

我有以下表单:

有没有办法在提交后向表单添加回调函数?基本上我将 upload.php 的结果回显到 iframe,我想做的是使用回调函数获取该信息。

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 and what I want to do is to get that information using a callback function.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

╰ゝ天使的微笑 2024-11-02 02:18:27

您想要使用 Ajax 提交帖子,并让 javascript 捕获结果中的回显并将 HTML 写入 iframe。

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.

凉月流沐 2024-11-02 02:18:27

正如 Gnostus 所说:使用 Ajax 提交表单,并在 ajax 完成并收到响应时附加一个函数...像这样(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();

不要忘记从表单中获取值,做一些事情就像:

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

并通过 ajax 调用提交它们......

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

你明白了。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文