我想将数据库查询结果以 JSON 格式传递给 jquery,为此我正在考虑这个第一个函数将从某个 C# 函数获取数据,然后将该数据作为输入传递给另一个 jQuery,以便在 Web 服务上进行处理。
我是新手..有人可以帮助我吗
第一个功能:
<script type="text/javascript">
var Result1;
var Result2;
function btnJquery_Click() {
$.ajax({ type: "POST",
url: "Default.asmx/GetData", // this will get data from c# function
data: {},
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function CallanotherFunction (response) { Result1= JSON.parse(response);}
});
function CallanotherFunction () {
$.ajax({ type: "POST",
url: "Default.asmx/GetData", // this will get data from c# function
data: Result1,
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function CallanotherFunction (response) {Result2= JSON.parse(response); }
});
}
</script>
这只是虚构的代码;行不通..请帮我写代码
尝试使用.done()
function btnJquery_Click() {
$.ajax({ type: "POST",
url: "Default.asmx/GetData", // this will get data from c# function
data: {},
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (response) {
Result1= JSON.parse(response);
}).done(function(Result1){
CallanotherFunction (Result1)
})
});
或
$.ajax({
type: "POST",
url: "Default.asmx/GetData", // this will get data from c# function
data: {},
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
Result1 = JSON.parse(data); //1st ajax data
$.ajax({
type: "POST",
url: "Default.asmx/GetData", // this will get data from c# function
data: Result1, //used 1st ajax data
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (response) {
Result2 = JSON.parse(response);//here 2nd ajax data based on first ajax call
}
});
}
});