Ajax调用不断触及错误函数

时间:2013-07-25 10:51:14

标签: javascript asp.net ajax jquery webmethod

我正在尝试使用bettertooltip设置页面中所有元素的title属性。

我从网络方法获取信息,但是呼叫一直在触及错误功能。

我的webmethod用于从sql server中提取一些信息并将其Searialize回到ajax sucess函数。我做错了什么?

这是我的javascript:

<script>
        $(document).ready(function () {
            var PrevIDs = $('a[alter="add_title"]'); //get all preview noded
            $.each(PrevIDs, function () {
                change_a_title(this);
            });


            $('.tTip').betterTooltip({ speed: 150, delay: 300 });
        });



        function change_a_title(obj) {
            var value1 = obj.id;
            var dataString = JSON.stringify({ e_num: value1 });
            $.ajax({
                type: "POST",
                async: false,
                url: "test_for title.aspx/return_event_details",
                data: dataString,
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (result) {
                    //result is an Object() returned from the server, we can use it and get the data from it, result.d has the response data
                    if (result.d) {
                        debugger;
                        var event = JSON.parse(result.d);
//                        var Titles = [" ניסיון ", " מין ", " ימים ", " שעות  "];
//                        var currentTitle = "<table>";
//                        for (var i = 0; i < Grades.length; i++) {
//                            debugger;
//                            currentTitle += "<tr><td style='text-align:center'><b>" + Titles[i] + "</b></td></tr><tr><td><div class='progress_wrapper pink_blue'><span class='pink_blue tooltip'>" + Grades[i] + "%</span><progress value='" + Grades[i] + "' max='100' class='pink_blue'></progress></div></td></tr>";

//                        }
//                        currentTitle += "</table>"
                        obj.title = event["name"];
                    }
                    else {

                    }
                },
                error: function (result) {
                    alert("Error Massage");
                }
            });
            //  debugger; 
            //   obj.title = currentTitle;
            //  obj.attr("title", currentTitle);
        }


    </script>

现在我只检查一个元素:(它被发送到“change_a_title”函数但是ajax调用失败):

<form id="form1" runat="server">
    <div>
        <a id="1" alter="add_title">ווקוו</a>
    </div>
    </form>

这是我的方法:

 [WebMethod]
    public static string return_event_details(string e_num)
    {
        dbservices db = new dbservices();

        act_event event1 = db.return_event_by_num(Convert.ToInt32(e_num));


        JavaScriptSerializer jSearializer = new JavaScriptSerializer();
        return jSearializer.Serialize(event1);
    }

1 个答案:

答案 0 :(得分:0)

嗯,sql查询错误,所以它抛出了错误。现在它工作正常