Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/405.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/88.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 简单ajax请求的jquery未定义错误_Javascript_Jquery_Ajax_Twitter Bootstrap_Canvasjs - Fatal编程技术网

Javascript 简单ajax请求的jquery未定义错误

Javascript 简单ajax请求的jquery未定义错误,javascript,jquery,ajax,twitter-bootstrap,canvasjs,Javascript,Jquery,Ajax,Twitter Bootstrap,Canvasjs,我已经包括了jquery,然后所有的ui js文件,因为很少有线程认为这个错误是由于依赖关系造成的。用户上传照片时使用canvasjs绘制图形 Uncaught TypeError: Cannot read property 'getTime' of undefined 具有所有必需依赖项的引导html。我认为某些循环问题或变量没有正确传递,但console.log根据canvasjs的所需数据点显示有效的json。如果这些点直接嵌入到该数据点中,则生成的图形不会出现任何错误或问题 我也尝

我已经包括了jquery,然后所有的ui js文件,因为很少有线程认为这个错误是由于依赖关系造成的。用户上传照片时使用canvasjs绘制图形

  Uncaught TypeError: Cannot read property 'getTime' of undefined
具有所有必需依赖项的引导html。我认为某些循环问题或变量没有正确传递,但console.log根据canvasjs的所需数据点显示有效的json。如果这些点直接嵌入到该数据点中,则生成的图形不会出现任何错误或问题

我也尝试过更新canvasjs的函数,但没有成功,我认为这不是必需的,因为这些数据都是成功传递的,所以没有传递空白数据。我怀疑for loop是罪魁祸首,但不知道如何以及为什么

$(document).ready(function() {
    (function() {

        $('#upload-form2').ajaxForm({
            dataType: 'json',
            success: function(data) {
               var sthtml;              
                var html = '',
                    downlo;
                for (var i = 0; i < data.length; i++) {
                    z = i + 1;
                    downlo = data[i];
                    html += '<tr id="' + i + '"><td>' + z + '</td></tr>';
                sthtml += downlo.stchart;

                }

// canvas graph starts here

        var chart = new CanvasJS.Chart("chartContainer",
    {     
      theme:"theme2",
      title:{
        text: "Game of Thrones, Viewers of the first airing on HBO"
      },
      data: [
      {        
        type: "spline",        
       dataPoints: [sthtml]
// this is the culprit dont know why but console.log shows correct canvasjs.min.js:103 Uncaught TypeError: Cannot read property 'getTime' of undefined
    //         dataPoints: [{ x: 3, y: 150 },{ x: 2, y: 14}]     
 //gives no error however my console.log output is exactly same in last line of this script 
 },
      {        
        type: "spline", 
       dataPoints: [{ x: 1, y: 450 },{ x: 2, y: 414}] 
      } 
      ],
    });
chart.render();

// canvas graph ends here

//console.log(sthtml);
            }
        })
    })();
});
$(文档).ready(函数(){
(功能(){
$('#upload-form2').ajaxForm({
数据类型:“json”,
成功:功能(数据){
var-sthtml;
var html='',
唐洛;
对于(变量i=0;i
您的sthtml应该是数组类型。您已经对sthtml使用了连接操作,该操作将sthtml转换为字符串。您需要使用数组推送操作来推送

$(document).ready(function() {
    (function() {

        $('#upload-form2').ajaxForm({
            dataType: 'json',
            success: function(data) {
               var sthtml=[];// sthhtml is array              
                var html = '',
                    downlo;
                for (var i = 0; i < data.length; i++) {
                    z = i + 1;
                    downlo = data[i];
                    html += '<tr id="' + i + '"><td>' + z + '</td></tr>';
                sthtml.push(downlo.stchart); // use push to push objects

                }

// canvas graph starts here

        var chart = new CanvasJS.Chart("chartContainer",
    {     
      theme:"theme2",
      title:{
        text: "Game of Thrones, Viewers of the first airing on HBO"
      },
      data: [
      {        
        type: "spline",        
       dataPoints: sthtml
// this is the culprit dont know why but console.log shows correct canvasjs.min.js:103 Uncaught TypeError: Cannot read property 'getTime' of undefined
    //         dataPoints: [{ x: 3, y: 150 },{ x: 2, y: 14}]     
 //gives no error however my console.log output is exactly same in last line of this script 
 },
      {        
        type: "spline", 
       dataPoints: [{ x: 1, y: 450 },{ x: 2, y: 414}] 
      } 
      ],
    });
chart.render();

// canvas graph ends here

//console.log(sthtml);
            }
        })
    })();
});
$(文档).ready(函数(){
(功能(){
$('#upload-form2').ajaxForm({
数据类型:“json”,
成功:功能(数据){
var sthtml=[];//sthhtml是数组
var html='',
唐洛;
对于(变量i=0;i
它有什么数据sthtml???@Dinesh response json数据是{x:1,y:450},{x:2,y:414}类似的type@Dinesh谢谢你的回答。我认为这是正确的方法,因为我现在没有得到错误,但是json正在被划分,所以图形没有显示出来。控制台日志显示的数据如下[“{x:3,y:33.6},”{x:4,y:62.2},“{x:5,y:121.2},”,“,x:0]我不知道怎么来的”,“我的json输出就是这样的{x:3,y:33.6}。我已经更改了json并删除了它,所以jquery将添加逗号,但我如何避免[and]“您控制服务器端代码吗?json格式完全错误。@Dinesh我控制服务器端代码,但这是根据canvasjs数据格式的要求。谢谢您的回答。我认为这是正确的方法,因为我现在没有收到错误,但json正在被划分,因此图形没有显示。控制台日志显示的数据如下[”{x:3,y:33.6},“{x:4,y:62.2},“{x:5,y:121.2},”,“,x:0]我不知道怎么来的”,“我的json输出就是这样的{x:3,y:33.6}”