我正在研究項目並面臨問題。無法找到我的代碼中有什麼問題。以下是我的代碼,不知道爲什麼Ajax url無法獲取Default.aspx的ReceivedMessageByIndexNumber函數。謝謝。通過Ajax傳遞參數
的JavaScript:
ReceivedMessage(1);
function ReceivedMessage(indexNumber)
{
$.ajax({
type: "Post",
url: "Default.aspx/ReceivedMessageByIndexNumber?indexNumber="+indexNumber,
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (response) {
var data = response.d;
for (var i = 0; i < data.length; i++) {
alert(data[i]);
}
},
failure: function (msg) {
$('#output').text(msg);
}
});
}
的Default.aspx:
[WebMethod]
public static bool ReceivedMessageByIndexNumber(int textIndex)
{
string connectionString = @"Data Source=localhost;Initial Catalog=NotificationSystem;Integrated Security=True";
using (SqlConnection connection = new SqlConnection(connectionString))
using (SqlCommand command = connection.CreateCommand())
{
connection.Open();
command.CommandText = @"SELECT TextWord FROM TextProperty WHERE TextIndex = '" + textIndex + "'";
command.ExecuteNonQuery();
return true;
}
}
你的查詢字符串參數預計將在服務器的服務器(textIndex) – 2014-10-08 14:00:34
我這樣做,但再次同樣的問題@代碼(indexNumber)來命名有不同的名稱主要曼 – user3817516 2014-10-08 14:02:13
我的答案是否適合您或發生了什麼?如果它確實有效,你可以將它標記爲答案?謝謝。 – Carter 2014-10-09 18:37:38