日期:2014-05-17  浏览次数:20457 次

$ajax无法调用数据
 var chart;
        function requestData() {
            $.ajax({
                type: "Post",
                url: "Test1.aspx/DataBank",

                contentType: "application/json; charset=utf-8",

                dataType: "json",
                success: function (data) {
                    var x = (new Date).getTime(),
                    y = data.Data[0].linespeed;
                    chart.series[0].addPoint([x, y], true, true);
                    // call it again after one second
                    setTimeout(requestData, 1000);
                },
                error: function (err) {
                    alert(err + "调用后台程序出现错误,请尝试刷新!");

下面是Test.aspx.cs文件中的DataBank函数
 
public string DataBank()
        {
            string json = "{\"Data\":[";
            if (!flag)
            {
                json += "{\"linespeed\":\"" + "0" + "\"}]}";
            }
            else
            {
                json += "{\"linespeed\":\"" + iDataChannels.getLineSpeed().ToString() + "\"}]}";
            }
            return json;
        }

问题就是启动网页时,$ajax无法成功加载数据。分不多,各位大大,请帮忙看看呀,这里拜谢了。

------解决方案--------------------
前台代码:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication1.WebForm1" %>

<!DOCTYPE html PUBLIC&nbs