【问题标题】:jQuery.load() with AJAX Kontactr formjQuery.load() 与 AJAX Kontactr 表单
【发布时间】:2011-03-07 22:35:37
【问题描述】:

在看到很多关于 jQuery.load() 如何处理要加载的内容中的标签的问题后,我看到 jQuery 去除了内联标签。但是,我想在我的站点中使用Kontactr 作为联系页面,并且它们嵌入的更好的 AJAX 是两个脚本标签,如下面的代码示例所示。如何解决 jQuery.load() 约束以使这些脚本标签在 jQuery.load(file, callback()) callback() 函数中运行?

index.html

<html>
<head>
    <!--include css, jquery, scripts -->
    <script type="text/javascript">
        $(document).ready(function() {
            $('#main_content').load('contact.html #main_content', function(){
                //what can I put here to run the Kontactr inline script code
                //when contact.html is loaded?
            });
        });
    </script>
</head>
<body>
    <div id="main_content"><!--content will load here--></div>
</body>
</html>

contact.html

<div id="main_content">
    <h1>Please Contact Us With The Form Below</h1>
    <!-- jQuery.load will strip out these script tags 
         and the form will not be embedded. -->
    <script type="text/javascript"> id = 1; </script>
    <script type="text/javascript" src="http://kontactr.com/wp.js"></script>
</div>

我想也许我可以将&lt;div id="contact_form"/&gt; 放在contact.html 中,然后在回调函数中评估脚本标签 $('#contact_form').html(//eval script tags result here);,但我不确定如何在语法上做到这一点。

【问题讨论】:

    标签: jquery load inline-scripting


    【解决方案1】:

    所以,万一其他人遇到这个问题,有一个非常简单的解决方案。

    http://kontactr.com/wp.js 脚本只是 document.write() 的 iframe 到页面。我最终做的是:

    <div id="main_content">
        <h1>Please Contact Us With The Form Below</h1>
        <center>
            <iframe id="kontactr-iframe" src="http://kontactr.com/w.php?id=1&referrer=http://www.theurlyourrequestingfrom.com&color=000000-FFFFFF-000000-FFFFFF" width="475px" height="475px" frameborder="0"></iframe>
        </center>
    </div>
    

    它就像一个魅力。

    注意:color 参数是可选的,id 参数特定于您的 Kontactr 帐户。 referrer 参数在 http://kontactr.com/wp.js 脚本中填充有 window.top.location.href。我只是把 $.load() 页面的 URL 放在那里。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-03-11
      • 1970-01-01
      • 1970-01-01
      • 2012-10-28
      • 1970-01-01
      相关资源
      最近更新 更多