返回带循环到ajax函数的值 [英] return value with loop to ajax funtion

查看:52
本文介绍了返回带循环到ajax函数的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 SqlDataReader xreader = xCmd.ExecuteReader(); 
while (xreader.Read())
{
return xreader [ 0 ]。ToString();
}

// ajax函数
$ .ajax({
type: POST
url: Main.aspx / GetDataID
data: {}
contentType: application / json; charset = utf-8
dataType: json
成功:函数(结果){
GetDataP(result.d);
}

});







问题是当我用循环返回值时....循环只运行一次并且一次返回循环是休息.....请给我一个解决方案

解决方案

.ajax({
type: POST
url: Main.aspx / GetDataID
data: {}
contentType: application / json; charset = utf-8
dataType: json
成功:函数(结果){
GetDataP(result.d);
}

});







问题是当我用循环返回值时....循环只运行一次,一次返回循环后就是.....请给我一个解决方案


使用下面这段代码。



列表< string> ; lstIDs =  new  List< string>(); 
SqlDataReader xreader = xCmd.ExecuteReader();
while (xreader.Read())
{
lstIDs.Add(xreader [ 0 ]。ToString()) ;
}
return lstIDs;
< / string > < / string >


SqlDataReader xreader = xCmd.ExecuteReader();
while (xreader.Read())
{
 return xreader[0].ToString();
}

//ajax function
$.ajax({
            type: "POST",
            url: "Main.aspx/GetDataID",
            data: "{}",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (result) {
                GetDataP(result.d);
            }

        });




problem is that when i return value with loop .... loop is run only one time and after one time return loop is break ..... please give me a solution

解决方案

.ajax({ type: "POST", url: "Main.aspx/GetDataID", data: "{}", contentType: "application/json; charset=utf-8", dataType: "json", success: function (result) { GetDataP(result.d); } });




problem is that when i return value with loop .... loop is run only one time and after one time return loop is break ..... please give me a solution


Use the following piece of code.

List<string> lstIDs = new List<string>();
SqlDataReader xreader = xCmd.ExecuteReader();
while (xreader.Read())
{
 lstIDs.Add(xreader[0].ToString());
}
return lstIDs;
</string></string>


这篇关于返回带循环到ajax函数的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆