在ajax jquery调用中获取html页面

时间:2011-08-17 00:55:35

标签: jquery asp.net ajax

最近我将我的应用程序上传到生产服务器,其中有ajax jquery调用我的webmethod ...它运行良好...在开发但是在生产时我得到了以下错误:

< !DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
< html xmlns="w3.org/1999/xhtml">  
 < head>< title> 
</ title>< /head> < body> < form name="form1" method="post" action="AddPollAJax.aspx" id="form1" >  < div > < input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="hP8DrZMpHGeABurXdr2IcRY8jMzK+5Ayj3BI0bptYaeZn7amHg1E4nNUCVS1+ScBxUQNKDzsG‌ ​gfP3Fnv7yq7JtdZV3o=" / > < /div > < div > < input type="hidden" name="__VIEWSTATEENCRYPTED" id="__VIEWSTATEENCRYPTED" value="" / > < /div > < div > < /div > < /form > < /body > < /html >

下面是我的webmethod

[WebMethod]
    public static Poll[] GetPollDetails(int pageSize, int currentPage)
    {
        SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["SiteSqlServer"].ConnectionString);
        SqlDataAdapter da = new SqlDataAdapter("sp_GetCollectionForPoll", con);
        da.SelectCommand.CommandType = CommandType.StoredProcedure;
        da.SelectCommand.Parameters.AddWithValue("@PageSize", pageSize);
        da.SelectCommand.Parameters.AddWithValue("@CurrentPage", currentPage);
        da.SelectCommand.Parameters.AddWithValue("@siteid", 1);
        DataSet dt = new DataSet();
        da.Fill(dt);
        List<Poll> _poll1 = new List<Poll>();
        foreach (DataRow row in dt.Tables[0].Rows)
        {
            Poll _poll = new Poll();
            _poll.QuestionID = Convert.ToInt32(row["questionID"]);
            _poll.Question = Utils.RemoveHtmlTags(row["question"].ToString());
            _poll.Published = row["Published"].ToString();
            _poll.Date = row["Date"].ToString();
            _poll.TotalRecords = Convert.ToInt32(dt.Tables[1].Rows[0]["TotalRow"].ToString());
            _poll.AnswerCount = Convert.ToInt32(row["AnsCount"].ToString());
            _poll1.Add(_poll);
        }
        return _poll1.ToArray();
    }

和我的javascript函数

 function GetPolls(pageSize, currentPage) {
        if (currentPage < 1) {
            alert("You are currently Viewing First Page cannot go back");
            return false;
        }

        try {
            $.ajax({
                type: "POST",
                url: "AddPollAJax.aspx/GetPollDetails",
                data: "{'pageSize':'" + pageSize + "','currentPage':'" + currentPage + "'}",
                contentType: "application/json",
                dataType: "json",
                success: function (msg) {
                    var data = msg.d;
                    if (_totalRecords == 0) {
                        _totalRecords = data[0].TotalRecords;
                    }
                    var totalPage = Math.ceil(_totalRecords / pageSize);
                    if (currentPage > totalPage) {
                        alert("You are currently viewing last page, cannot go forward");
                        return false;
                    }
                    var s = "<table border='0' width='100%' cellpadding='5' style='border-collapse:collapse'><thead><tr style='background-color:#C4F3E3'><th>EDIT</th><th>ID</th><th>Question</th><th>Options</th><th>Created Date</th><th>Published</th></tr></thead><tfoot width='100%' style='background-color:#C4F3E3'><tr><td colspan='6' align='center'><input type='button' style='font:normal 15px ALGERIAN, arial;' border='solid 0px' id='btnPrevious' onclick='GetPolls(" + $("#pageSize").val() + "," + (parseInt(currentPage) - 1) + ")' id='btnPrevious' value='PREVIOUS' />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type='button' style='font:normal 15px ALGERIAN, arial' id='btnNext' onclick='GetPolls(" + $("#pageSize").val() + "," + (parseInt(currentPage) + 1) + ")' value='NEXT' /></td><tr></tfoot><tbody>";
                    var iChecked;
                    for (i = 0; i < data.length; i++) {
                        if (data[i].Published == "True") { iChecked = "checked" } else { iChecked = "" };
                        if (i % 2 != 0) {
                            s += "<tr style='background-color:#C4F3E3'><td width='7%' align='center'><img type='button' style='cursor:pointer' src='/images/edit.gif' value='EDIT' onclick='getData(" + data[i].QuestionID + ")' />&nbsp;&nbsp;<img type='button' style='cursor:pointer' src='/images/delete.gif' value='EDIT' onclick='DeletePollQuestion(" + data[i].QuestionID + ")' /></td><td width='2%' align='center' class='gridText'>" + data[i].QuestionID + "</td><td style='padding-left:5px;' class='gridText'>" + data[i].Question + "</td><td valign='middle' width='5%' align='center' class='gridText'>" + data[i].AnswerCount + "</td><td width='10%' align='center' class='gridText'>" + data[i].Date + "</td><td width='10%' align='center'><input type='checkBox' " + iChecked + " disabled=disabled></td></tr>";
                        }
                        else {
                            s += "<tr style='background-color:#74DDB7'><td width='7%' align='center'><img type='button' style='cursor:pointer' src='/images/edit.gif' value='EDIT' onclick='getData(" + data[i].QuestionID + ")' />&nbsp;&nbsp;<img type='button' style='cursor:pointer' src='/images/delete.gif' value='EDIT' onclick='DeletePollQuestion(" + data[i].QuestionID + ")' /></td><td width='2%' align='center' class='gridText'>" + data[i].QuestionID + "</td><td style='padding-left:5px;' class='gridText'>" + data[i].Question + "</td><td valign='middle' width='5%' align='center' class='gridText'>" + data[i].AnswerCount + "</td><td width='10%' align='center' class='gridText'>" + data[i].Date + "</td><td width='10%' align='center'><input type='checkBox' " + iChecked + " disabled=disabled></td></tr>";
                        }
                    }
                    s += "</tbody></table>";
                    document.getElementById("jqGrid").innerHTML = s;
                },
                error: function (data) {
                    alert("Error: " + data.responseText);
                }
            });
        }
        catch (err) {
            alert(err.Description);
        }
    }

任何人都可以帮我解决这个错误:

2 个答案:

答案 0 :(得分:0)

试试这个

 data: "{'pageSize':" + pageSize + ",'currentPage':" + currentPage + "}",

而不是

 data: "{'pageSize':'" + pageSize + "','currentPage':'" + currentPage + "'}",

答案 1 :(得分:0)

而不是

return _poll1.ToArray();

仅使用

return _poll1();

Javascriptserializer会自动转换为JSON对象。