0
我想使用bettertooltip爲我的頁面中的所有元素設置標題屬性。Ajax調用一直打錯誤函數
我從webmethod獲取信息,但該調用一直打錯誤函數。
我的webmethod用於從sql server中提取一些信息並將其返回到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>
現在我只檢查一個elemnt:(它被髮送到 「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);
}
控制檯記錄錯誤消息,看看它給出了什麼,也檢查網絡選項卡的錯誤。 – Vishwanath
嘗試添加[ScriptMethod] @服務器端 – rps
我該怎麼做? – Dvirski