来自远程url的javascript显示表单

来自远程url的javascript显示表单,javascript,Javascript,我的URL中有动态表单。我想编写一个javascript,这样当用户将该javascript粘贴到他们的网页时,表单应该显示出来 <script type="text/javascript"> window.location.href = "http://myserver/2a249ccf59e272abb8e7b8582560a45c" </script> window.location.href=”http://myserver/2a249ccf59e272abb

我的URL中有动态表单。我想编写一个javascript,这样当用户将该javascript粘贴到他们的网页时,表单应该显示出来

<script type="text/javascript">
window.location.href = "http://myserver/2a249ccf59e272abb8e7b8582560a45c"
</script>

window.location.href=”http://myserver/2a249ccf59e272abb8e7b8582560a45c"
问题是使用上面的代码,url重定向。我想避免重定向
我试过iFrame,但我不想按照要求使用它们

您需要使用AJAX来获取远程页面。您必须从交付网页的服务器获取网页,以避免同源策略问题

我建议使用库来处理AJAX请求。jQuery内置了AJAX函数,但也可以使用其他函数。使用jQuery

// be sure to include jQuery library in the head of your document...

// general wrapper to execute code only after all page elements have loaded
$(function(){
    $.get("http://myserver/2a249ccf59e272abb8e7b8582560a45c",function(data,status){
        // put the fetched data (your html form) at the end of the existing body content
        // you could put it somewhere else by changing the `body` selector
        $("body").append(data)
    })
})

你的意思是想转义html,使其不被呈现和执行,而只在页面上直观地显示吗?不完全是这样。url的内容中有动态表单。如果将url粘贴到浏览器中,将加载并显示一个表单。我想用javascript做同样的事情。基本上,我想使用javascript获取url内容。好吧,这确实是一个关于AJAX的问题,以及如何将HTML注入页面。你能给我一个解决方案吗?到目前为止,你是如何发现堆栈溢出的?如果你给自己一个名字,并继续使用你的帐户,将来会有更多的人回答你的问题。