Asynchronous cross-domain POST request via JavaScript?

后端 未结 5 1850
一整个雨季
一整个雨季 2020-12-24 09:37

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

相关标签:
5条回答
  • 2020-12-24 10:06

    If the data returned from the cross domain post is JSON, then you can dynamically add a script tag pointing to the URI that returns the data. The browser will load that "script" which then you can access from other javascript.

    0 讨论(0)
  • 2020-12-24 10:06

    You can't do anything cross-domain using javascript. You'd have to use a backend language like PHP or asp or something.

    0 讨论(0)
  • 2020-12-24 10:07

    IF you want to make cross domain requests you should either made a JSON call or use a serverside proxy. A serverside proxy is easy to set up, not sure why people avoid it so much. Set up rules in it so people can not use the proxy to request other things.

    0 讨论(0)
  • 2020-12-24 10:15

    YUI3's IO object offers cross-domain requests, however it does so using a small Flash control it embeds on the page.

    While there is work going into secure cross-domain requests from JavaScript, at this time, you need to use a plugin like Flash or Silverlight as a bridge with which to make the request.

    0 讨论(0)
  • 2020-12-24 10:19

    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.

    Try something like this:

    <iframe id='RS' name='RS' src='about:blank' onload='loaded()'></iframe>
    
    <form action='wherever.php' target='RS' method='POST'>...</form>
    

    script block:

    var loadComplete = 0
    function loaded() {
        //avoid first onload
        if(loadComplete==0) {
            loadComplete=1
            return()
        }
        alert("form has loaded")
    }
    
    0 讨论(0)
提交回复
热议问题