Javascript 将值传递给ajax函数
我正在使用我的第一个应用程序,我试图将值传递给ajax函数,但我不知道如何继续 有什么需要帮忙的吗 这是我的代码: html:这是必须传递值的链接,例如9Javascript 将值传递给ajax函数,javascript,jquery,ajax,Javascript,Jquery,Ajax,我正在使用我的第一个应用程序,我试图将值传递给ajax函数,但我不知道如何继续 有什么需要帮忙的吗 这是我的代码: html:这是必须传递值的链接,例如9 <a id="btnRockArg" data-role="button" data-transition="slide" href="category.html">Categorías</a> 非常感谢你 $.ajax({ url: 'http://.....o
<a id="btnRockArg" data-role="button" data-transition="slide" href="category.html">Categorías</a>
非常感谢你
$.ajax({
url: 'http://.....org/api/get_category_posts',
data:'id='+valueCatRockArg+'&count=5&order=desc',
type: 'GET',
dataType: 'jsonp',
success: function(data){
var source = $("#category-template").html(); //Get the HTML from the template in the script tag
var template = Handlebars.compile(source); // compilamos la plantilla
var blogData = template(data); // en data se almacena el contenido que nos viene de wordpress
$('#category-data').html(blogData); // mostramos el contenido
$('#category-data').trigger('create');
dfd.resolve(data);
},
error: function(data){
console.log(data);
}
});
尝试此方法,使用data aAttribute传递参数使用$.ajax的data属性发送数据。OP为什么要尝试此方法?OP的代码有什么问题?为什么你的答案能解决?请不要玩“点差”游戏。解释你的答案。非常感谢!想想看,html如何将值发送到数据?@pablo无法回答您的问题。如果我没有很好地解释,我很抱歉,我的英语真的很差,而且我对应用程序很陌生。我的问题是,如何将值传递给valueCatRockArg?或者如何在html中构造链接以将值发送到valueCatRockArg?感谢您againvar valueCatRockArg=$selector.val;
$.ajax({
url: 'http://.....org/api/get_category_posts',
data:'id='+valueCatRockArg+'&count=5&order=desc',
type: 'GET',
dataType: 'jsonp',
success: function(data){
var source = $("#category-template").html(); //Get the HTML from the template in the script tag
var template = Handlebars.compile(source); // compilamos la plantilla
var blogData = template(data); // en data se almacena el contenido que nos viene de wordpress
$('#category-data').html(blogData); // mostramos el contenido
$('#category-data').trigger('create');
dfd.resolve(data);
},
error: function(data){
console.log(data);
}
});