我正在研究项目并面临问题。无法找到我的代码中有什么问题。以下是我的代码,不知道为什么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