通过JavaScript异步跨域POST请求? [英] Asynchronous cross-domain POST request via JavaScript?

查看:128
本文介绍了通过JavaScript异步跨域POST请求?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以创建一个表单,并使用做一个POST请求到任何网站,事情的形式方法不是异步的,我需要知道什么时候该页面加载完毕。我试着瞎搞本使用iframe里面的一种形式,但没有成功。

I could just create a form and use that to do a POST request to any site, thing is the FORM method isn't asynchronous, I need to know when the page has finished loading. I tried messing around with this using an iframe with a form inside, but no success.

任何想法?

修改

不幸的是我有过响应数据无法控制,它从XML,JSON,以简单的文字变化。

unfortunately I have no control over the response data, it varies from XML, json to simple text.

推荐答案

您可以捕获的onload 事件的 IFRAME 。定位您表格来的iframe和监听onload事件。您将无法访问该iframe的内容虽然只是事件。

You can capture the onload event of an iframe. Target your form to the iframe and listen for the onload. You will not be able to access the contents of the iframe though, just the event.

尝试是这样的:

<iframe id='RS' name='RS' src='about:blank' onload='loaded()'></iframe>

<form action='wherever.php' target='RS' method='POST'>...</form>

脚本块:

var loadComplete = 0
function loaded() {
    //avoid first onload
    if(loadComplete==0) {
        loadComplete=1
        return()
    }
    alert("form has loaded")
}

这篇关于通过JavaScript异步跨域POST请求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆