【问题标题】:why is my javascript in an called ajax doesn't work? with jquery为什么我在调用 ajax 中的 javascript 不起作用?用jQuery
【发布时间】:2011-09-18 02:32:04
【问题描述】:

好吧,可以说我正在做类似的事情

http://localhost/ajax/social/pull/facebookstatus

在我的/ajax/social/pull/facebookstatus 上有一个类似的脚本

<script type="text/javascript" src="https://www.google.com/jsapi"></script>
    <script type="text/javascript">
      // Load the Visualization API and the piechart package.
      google.load('visualization', '1', {'packages':['corechart']});

      // Set a callback to run when the Google Visualization API is loaded.
      google.setOnLoadCallback(drawChart);

      // Callback that creates and populates a data table, 
      // instantiates the pie chart, passes in the data and
      // draws it.
      function drawChart() {

      // Create our data table.
      var data = new google.visualization.DataTable();

回到我试图打电话的问题(让我们说http://localhost/myprofile

    $.ajax({  
        type: "POST",                    // Using the POST method  
        url: "/ajax/social/pull/facebookstatus",      // The file to call  
        data: myfbdata, 
        dataType: 'html',
        success: function(data) {
        $('#ajax-placeputfb').hide().fadeIn(3000).html(data);
        }  
    });

/ajax/social/pull/facebookstatus 上的脚本在 http://localhost/myprofile 上加载时不起作用

有问题吗?

谢谢

亚当斋月

【问题讨论】:

  • 我无法连接到您的本地主机 :)
  • 它是lets say 伙计:D,无论如何我们不能在 javascipt ajax 调用上加载 javascript 吗?
  • 它确实加载了,但是我显示图表的 JavaScript 没有显示,它显示了除此之外的所有其他内容。
  • 你的 drawChart() 函数被调用了吗?
  • 进行 AJAX 调用时服务器的 HTTP 响应是什么?是否有 HTTP 响应?

标签: jquery ajax


【解决方案1】:

这是一个相关的问题吗? When loading an html page via ajax, will script tags be loaded?

当 lib 未包含在 &lt;head&gt; 中时,我遇到了类似的问题

也许您可以尝试将其包含在主文档的 &lt;head&gt; 标记中

&lt;script type="text/javascript" src="https://www.google.com/jsapi"&gt;&lt;/script&gt;

【讨论】:

  • 是的,我知道我正在使用 dataType: 'html'.. edit* 我试图将一部分(只是像 {ajaxhere} &lt;div id="facebookstatus"&gt;blabla&lt;/div&gt;&lt;div id="facebook-graph"&gt;&lt;/div&gt; 这样的 div )放入页面。
  • 查看是否设置了名为 google 的 var。您可以在
  • 是的,这就是您看到的问题。您是否尝试按照我的回答将该库包含在 标记中?
  • edit* 它以某种方式将我重定向到一个空白页面,它说,等待谷歌,然后空白。所以它只是谷歌?因为当我从/ajax/social/pull/facebookstatus打开它时它工作正常@
猜你喜欢
  • 1970-01-01
  • 2011-10-31
  • 2020-05-15
  • 2015-08-14
  • 2021-10-11
  • 1970-01-01
  • 1970-01-01
  • 2012-05-12
相关资源
最近更新 更多