Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/295.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用ajax用数据填充jQuery autoscroll插件;模板函数从未启动_C#_Jquery_Asp.net - Fatal编程技术网

C# 使用ajax用数据填充jQuery autoscroll插件;模板函数从未启动

C# 使用ajax用数据填充jQuery autoscroll插件;模板函数从未启动,c#,jquery,asp.net,C#,Jquery,Asp.net,我正在尝试使用一个名为jQuery的插件在我的网站上显示评论。然而,我正在努力使用AJAX从数据库中提取注释,而且从未调用模板函数 $(".Reviews").autobrowse({ url: function (offset) { //return Healthimized.Services.ClientUserServices.LoadClientUserReviews(1, LoadCustomerToSelectOption, ErrorHandler, onT

我正在尝试使用一个名为jQuery的插件在我的网站上显示评论。然而,我正在努力使用AJAX从数据库中提取注释,而且从未调用
模板
函数

$(".Reviews").autobrowse({
    url: function (offset) {
        //return Healthimized.Services.ClientUserServices.LoadClientUserReviews(1, LoadCustomerToSelectOption, ErrorHandler, onTimeOut)
        $.ajax({
            type: "POST",
            url: 'Services/ClientUserServices.asmx/GetAllSpecialities',
            //data: parameters,
            contentType: "application/json; charset=utf-8",
            //data: { fromDate: new Date(), toDate: new Date(), clientUserId:1},
            //data: "{'fromDate':'" + startFrom + "','toDate':'" + endTo + "','clientUserId':'" + doctorId + "'}",
            dataType: "json",
            //data: 'fromDate=' + new Date() + '&toDate=' + new Date() + '&clientUserId='+1,
            success: function (msg) {
                return "http://twitter.com/status/user_timeline/ParisHilton.json?count=10&page=OFFSET&callback=?".replace(/OFFSET/, 1+Math.round(offset/10));
            },
            error: function (e) {
                $(divToBeWorkedOn).html("Unavailable");
            }
        });
    },
    template: function (response) {
        var markup='';
        for (var i=0; i<response.length; i++) {
            markup+='<div style="background:rgba(0, 0, 0, 0.1);margin: 2% 2% 2% 2%;border-radius: 0.5em 0.5em 0.5em 0.5em;"><table>';
            markup += '<tr><td>';
            markup += '<img src="' + response[i].user.profile_image_url + '" /></td>';
            markup += '<td style="margin-top:-15px">'+response[i].text+'</td>';
            markup += '</tr></table></div>';
        }
        return markup;
    },
    itemsReturned: function (response) { return response.length; },
    max: 100,
    loader: '<div class="loader"></div>',
    sensitivity: 100,
    finished: function () { $(this).append('<p style="text-align:center"><b>No More Reviews to show</b></p>') }
    });
});
$(“.Reviews”).autobrowse({
url:函数(偏移量){
//返回Healthimized.Services.ClientUserServices.LoadClientUserReviews(1,LoadCustomerToSelectOption,ErrorHandler,onTimeOut)
$.ajax({
类型:“POST”,
url:'Services/ClientUserServices.asmx/GetAllSpecialities',
//数据:参数,
contentType:“应用程序/json;字符集=utf-8”,
//数据:{fromDate:new Date(),toDate:new Date(),clientUserId:1},
//数据:“{'fromDate':'“+startFrom+”,'toDate':'“+endTo+”,'clientUserId':'“+doctorId+”}”,
数据类型:“json”,
//数据:“fromDate=”+new Date()+”&toDate=“+new Date()+”&clientUserId=”+1,
成功:功能(msg){
返回“http://twitter.com/status/user_timeline/ParisHilton.json?count=10&page=OFFSET&callback=?“.replace(/OFFSET/,1+数学四舍五入(OFFSET/10));
},
错误:函数(e){
$(divToBeWorkedOn.html(“不可用”);
}
});
},
模板:函数(响应){
var标记=“”;

对于(var i=0;i首先,您的代码看起来像是断开连接的代码片段的混合。其次,此插件适合使用RESTful服务,其中参数通过查询字符串发送。要调用ASP.NET web服务方法,您必须通过ajax请求
数据
对象传递参数。此外,ASP.NET包装了ajax请求-响应in JSON对象,其中实际响应数据存储在
d
属性中

基于所有这些事实,您需要稍微更改插件代码,以便将其与ASP.NET web服务方法一起使用。要更改此插件代码,请执行以下操作:

if (options.postData)
{
    var data = null;
    if (typeof options.postData == "function")
    {
        data = options.postData();
    }
    else
    {
        data = options.postData;
    }

    jQuery.post(options.url(currentOffset), data, ajaxCallback, "json").error(options.onError);
}
else
{
    jQuery.getJSON(options.url(currentOffset), ajaxCallback).error(options.onError);
}
更改代码:

if (options.postData) {
    var data = null;
    if (typeof options.postData == "function") {
        data = options.postData(currentOffset);
    }
    else {
        data = options.postData;
    }

    jQuery.ajax({
        url: options.url(),
        type: "POST",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        data: data,
        success: ajaxCallback,
        error: options.onError
    });
}
else {
    jQuery.getJSON(options.url(currentOffset), ajaxCallback).error(options.onError);
}

让我们考虑一下Web服务代码如下:

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
[System.Web.Script.Services.ScriptService]
public class ClientUserServices : System.Web.Services.WebService
{
    [WebMethod]
    public string[] GetAllSpecialities(int index)
    {
        return Enumerable.Range(1, 20).Select(id => Guid.NewGuid().ToString()).ToArray();
    }
}
然后,您可以使用带有以下代码的
GetAllSpecialities
方法:

<script type="text/javascript">
     $(function () {
          $("#Reviews").autobrowse({
               url : '<%= ResolveClientUrl("~/Services/ClientUserServices.asmx/GetAllSpecialities") %>',
               postData: function (index) {
                    return "{ 'index' :" + index + "}";
               },
               template: function (response) {
                    response = response.d;
                    var markup = '';
                    for (var i = 0; i < response.length; i++) {
                         markup += "<div>" + response[i] + "</div>";
                    }
                    return markup;
               },
               itemsReturned: function (response) {
                    return response.d.length;
               },
               offset: 0,
               max: 10000,
               useCache: true,
               expiration: 1,
               onError: function (error) {
               }
          });
     });
</script>

<div id="Reviews">
</div>

$(函数(){
$(“#评论”).autobrowse({
url:“”,
postData:函数(索引){
返回“{'index':“+index+”}”;
},
模板:函数(响应){
响应=响应d;
var标记=“”;
对于(变量i=0;i
您好,谢谢您的回复。我已将插件js代码更改为您提到的,并根据您给出的示例更新了我的脚本,以便调用服务。现在不再调用web服务。现在不调用web服务。现在有什么问题吗?谢谢。