2
我有一个jQuery的Ajax的WebMethod呼叫提供的条件从一个WebMethod的值,如下所示:返回基于的WebMethod
<script type="text/javascript">
$(document).ready(function() {
$("#btnsubmit").click(function() {
var arr = new Array();
arr.push($("#control1").val()); arr.push($("#control2").val()); arr.push($("#control13 option:selected").val()); arr.push($("#control4 option:selected").val()); arr.push($("#control15 option:selected").val());
var requestedData = JSON.stringify(arr);
requestedData = "{'details':'" + requestedData + "'}";
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "EmployeeDemotion.aspx/Save",
data: requestedData,
dataType: "json",
success: function (result) {
//check the value returned from the WebMethod and provide alerts accordingly
},
error: function (result) {
alert("Error");
}
});
});
});
</script>
和,将WebMethod是如下:
[WebMethod(EnableSession = true)]
public static InsertDetails[] Save(string details)
{
DataTable dt = new DataTable(); DataTable dts = new DataTable();
List<InsertDetails> data = new List<InsertDetails>();
JavaScriptSerializer js = new JavaScriptSerializer();
string[] Tags = js.Deserialize<string[]>(details);
object[] obj = new object[8];
obj[0] = Tags[0].ToString(); obj[1] = Tags[1].ToString(); obj[2] = Tags[2].ToString(); obj[3] = Tags[3].ToString();
obj[4] = Tags[4].ToString();
int a = //say condition 1
int b = //say condition 2
if (a< b)
{
//insert into database and set a value which says the insertion has succeeded
}
else
{
//alert that data cannot be inserted
}
return data.ToArray();
}
现在我需要将任何可能的类型(布尔,数组,字符串,整数或其他)的值返回给ajax方法,以便ajax方法中的成功函数提醒插入状态(如te片段中的注释)即;一个值应该与最后一条语句一起返回“return data.ToArray();”到ajax方法。 我不需要返回元素'data',验证插入的值应该与'data'一起返回,或者以任何其他形式返回。
我需要两个案例1和2 ...谢谢Manish .. – 2013-05-14 05:44:01