客户端错误TypeError:a未定义

时间:2014-04-10 17:58:33

标签: c# jquery asp.net ajax webmethod

我从Webmethod&获取数据它需要绑定到一个表。但是我的Jquery函数没有成功。因为Ajax调用错误而没有调用webmethod。

我的Web方法

 [WebMethod, ScriptMethod]
public static List<UploadedFiles> GetAllUploadedFiles()
{
    List<UploadedFiles> UploadedFilesDetails = new List<UploadedFiles>();
    try
    {
        SqlCommand comGetAllFiles = new SqlCommand("SP_GetAllUploadedFiles", conDB);
        comGetAllFiles.CommandType = CommandType.StoredProcedure;
         if (conDB.State == ConnectionState.Closed)
            conDB.Open();

        SqlDataReader rdr = comGetAllFiles.ExecuteReader();
        DataTable dt = new DataTable();
        dt.Load(rdr);
        foreach (DataRow r in dt.Rows)
        {
            UploadedFilesDetails.Add(new UploadedFiles
            {
                Id = (int)r["Id"],
                UserId =(Guid)r["UserId"],
                FilePath = r["FilePath"].ToString(),
                Date =(DateTime) r["Date"]

            });
        }

    }
    catch(Exception ee)
    {
    }
    finally
    {
        conDB.Close();
    }
    return UploadedFilesDetails;

我的Ajax功能

 <script>
     $(function () {
         LoadUploadFiles();
     });

     function LoadUploadFiles() {

        var url = '<%=ResolveUrl("WebMethods.aspx/GetAllUploadedFiles") %>';
        $.ajax({
            url: url,
            type: "POST",
            dataType: "json",
            contentType: "application/json; charset=utf-8",
            success: function (Result) {
                alert("x");//<-- This alert firing
                $.each(Result.d, function (key, value) {
                    alert(Result.d); //<-- Thisone not firing
                    $("#uploaddata").append($("<table><tr></tr></table>").val
                     (value.Id).html(value.FilePath));

                });
            },
            error: function (e, x) {
                alert(x.ResponseText);
            }
        });
    }
 </script>

0 个答案:

没有答案