How to make an ajax call in API using Framework7

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

+4


source to share


4 answers


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



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);
});

      

+7


source


This is the same as a normal ajax call. use $$ instead of $ as $ DOM is assigned by $$.



$$.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');
        }

    }
    }); 

      

+1


source


Framework7 uses syntax similar to jQuery ajax. The POST call can be as follows:

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

      

See the DOM section for more examples of the official documentation for Framework7.

0


source


Framework7 comes with a handy request library for handling XHR (Ajax) requests right out of the box

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

      

framework7.io/docs

-3


source







All Articles