0

我正在提交一个带有 ajax 的表单并打开一个带有响应数据的 Colorbox:

$("#submitB").click(function () {
    $.post("/previewproposal", $("#proposal-form").serialize(), function(data){$.colorbox({html:data});}, "html");
});

渲染出来的html是这样的:

<script type="text/javascript">
    $(document).ready(function(){

        function plotData()
        {
            var dataArray = ...;
            var options = ...;

            $.plot($("#placeholder"), dataArray, options);
        }

        plotData();
    });
</script>

<div id="placeholder" style="float:left;margin:0;font-size:8pt;width:540px;height:180px;"></div>

动态生成的 div 之一是 Flot 图占位符。我目前收到以下错误:

uncaught exception: Invalid dimensions for plot, width = null, height = null

Flot 绘图功能需要绘图占位符 div 的宽度和高度才能工作。所以我在想我的情节占位符 div 在情节函数被绑定/调用时没有加载到 DOM 中?经过大量谷歌搜索并找到与此类似的问题后,我找不到如何完成这项工作的示例。如何在这里进行故障排除?提前致谢。

4

1 回答 1

0

您需要使您的 ajax 同步,但使用包装器 $.post() 是不可能的。所以将其更改为:

$.ajax({
  type: "POST",
  async:false,
  url: "/previewproposal",
  data: $("#proposal-form").serialize(),
  success: function(data){
         $.colorbox({html:data});
  },
  dataType: 'html'
});

//you can call plotData() here...
于 2013-02-28T17:40:42.790 回答