首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何从use服务中使用jQuery ajax请求来实现可扩展的v3?

如何从use服务中使用jQuery ajax请求来实现可扩展的v3?
EN

Stack Overflow用户
提问于 2017-01-16 09:15:26
回答 1查看 1.2K关注 0票数 1

我不知道为什么,但footable文档只显示了一种从文件中获取数据的方法,而不是从why服务中获取数据,所以我尝试了各种组合,将数据以json格式返回到footable实例中,但没有成功。他们的示例显示了以下内容:

代码语言:javascript
复制
$('.table').footable({
    "rows": $.get('rows.json')
});

(假设已经定义了列),这是可行的。但是,在我的ajax查询中,我尝试

代码语言:javascript
复制
$('.table').footable({
    "rows": data.d
});

并且没有发生错误,数据的格式是正确的(使用在线JSON模式检查器进行了验证),但是什么也没有发生(控制台中没有错误)。

我彻底测试了ajax查询(可以工作,我甚至可以解析返回的data.d ),所以我不知道如何继续。

代码语言:javascript
复制
$.ajax({
    type: "POST",
    url: "/Search.asmx/GetListingsByPageSort",
    data: '{"sp":' + JSON.stringify(sp) + '}',
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    success: function (data) {
        $('.table').footable({
            "rows": data.d
        });
    },
    error: function (xhr, status) {
        alert("fail: " + status);
    }
});

HTML是

代码语言:javascript
复制
    <table class="table" data-paging="true">
<thead>
        <tr>
            <th class="hdrcolVdr" data-class="expand" data-type="html" data-name="vendor">Vendor </th>
            <th class="hdrcolMan" data-breakpoints="xs sm" data-type="html" data-name="manufacturer">Manufacturer </th>
            <th class="hdrcolProd" data-breakpoints="xs sm md" data-type="html" data-name="product_name">Product </th>
            <th class="hdrcolPrice" data-breakpoints="xs" data-type="html" data-name="price">Price </th>
            <th class="hdrcolI" data-breakpoints="xs sm" data-type="html">Info </th>
        </tr>
    </thead>
    </table>

被难住了。

EN

回答 1

Stack Overflow用户

发布于 2017-03-29 20:10:15

我发现(经过艰苦的工作)问题来自于GET/POST响应的异步方式。在我的代码中,这是可行的:

rows : $.get('js/rw1.json')

但这并不管用:

rows : $.get("rest.php")

即使它们都给出了相同的值(可以看到跟踪网络流量)。

我已经解决了在同步模式下强制jQuery等待GET响应的问题。可能不是一个很好的解决方案,但它是有效的。这是我的代码:

rows : ajaxRows();

其中,ajaxRows是:

代码语言:javascript
复制
function ajaxRows(){
    var retu;
    jQuery.ajaxSetup({async:false});        
    retu = $.get("rest.php");
    jQuery.ajaxSetup({async:true});     
    return retu;            
}

在你的代码中,也许你应该添加到$.ajax参数中:

async:false

HTH

马可

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41668194

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档