简体   繁体   English

我们可以在一个函数中同时拥有ajax和jquery脚本吗?

[英]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? 我们在哪里可以同时使用ajax和Jquery?

For example we can create new elements with jquery like this: 例如,我们可以使用jquery创建新元素,如下所示:

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. 将“ url”视为服务返回的json形式的百分比值。

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

Also as mentioned by @Rajesh use jquery methods to style the elements. 就像@Rajesh提到的那样,使用jquery方法来设置元素的样式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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