javascript 如何使用 Framework7 在 API 中调用 ajax

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27740138/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-28 07:55:17  来源:igfitidea点击:

How to do ajax call in an API using Framework7

javascriptajaxhtml-framework-7

提问by Sydney Loteria

How can I do an ajax call using Framework7? I already know how to do ajax call using jQuery but I don't know how to do it in Framework7. I am using this for calling an API that returns data.

如何使用 Framework7 进行 ajax 调用?我已经知道如何使用 jQuery 进行 ajax 调用,但我不知道如何在 Framework7 中进行。我正在使用它来调用返回数据的 API。

回答by Vladimir Kharlampidi

You can include jQuery or use default Dom7 library, it has the same Ajax methods:

您可以包含 jQuery 或使用默认的 Dom7 库,它具有相同的 Ajax 方法:

var $$ = window.Dom7;

//do get request
$$.get('path-to-file.php', {id: 3}, function (data) {
  console.log(data);
});

//do post request
$$.post('path-to-file.php', {id: 3}, function (data) {
  console.log(data);
});

//get JSON request
$$.getJSON('path-to-file.js', function (json) {
  console.log(json);
});

回答by prasanna puttaswamy

It is same as regular ajax calling. use $$ instead of $ since $DOM is assigned to $$.

它与常规 ajax 调用相同。使用 $$ 而不是 $,因为 $DOM 被分配给 $$。

$$.ajax({
    url:url2,
    data:{'json_order':jsonOrder},
    type:'POST',
    beforeSend:function(){
    myApp.showPreloader('Please Wait');
    },
    success:function(data)
    {
        myApp.hidePreloader();
        console.log(data);
        if(data =='success')
        {

            alert('success');
        }
        else
        {
            alert('no data');
        }

    }
    }); 

回答by J.C. Gras

Framework7 use a syntax similar to jQuery's ajax. A POSTcall could be as follows:

Framework7 使用类似于 jQuery 的 ajax 的语法。一个POST调用可能如下:

$$.post('auth.php', {username:'foo', password: 'bar'}, function (data) {
  $$('.login').html(data);
  console.log('Load was performed');
});

You can find more examples in the DOM sectionof the official Framework7 documentation.

您可以在官方 Framework7 文档的DOM 部分找到更多示例。

回答by salman samadi

Framework7 comes with handy Request library to work with XHR requests (Ajax) right from the box

Framework7 带有方便的请求库,可以直接从框中处理 XHR 请求(Ajax)

app.request.post('http://localhost:4103/api/RepIO/List', function (data) {
var obj = JSON.parse(data);

framework7.io/docs

framework7.io/docs