简体   繁体   中英

Can we have both ajax and jquery scripts in one function?

I am working on an interactive project where interface showing graphs and related data to each graphs. I am thinking a way that, How can i get data from server and stylize the data and display those in graphs?

I am not sure. where can we use both ajax and Jquery in one function or not?

For example we can create new elements with jquery like this:

function set_value() {
    var data2 = document.getElementById('div_id');
    data2.style.width = "100%";
    data2.innerText = "Economics";
    var delay = 700;
    setTimeout(function () {
        var element = document.createElement("i");
        element.style.cssFloat = "right";
        element.appendChild(document.createTextNode('100%'));
        data2.appendChild(element);
    }, delay);
}

I want to get those percentage values from Database and i am not sure. how to do this? please someone help me. thank you!

Considering "url" to be the service returning percentage value in json form.

$.ajax({
   url:url,
   success:function(response) {
     call_your_function(response.percentage);
   }
});

Also as mentioned by @Rajesh use jquery methods to style the elements.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM