Javascript 从函数本身内部的按钮调用jquery函数
下面是调用webservice以返回json的代码Javascript 从函数本身内部的按钮调用jquery函数,javascript,jquery,jquery-mobile,Javascript,Jquery,Jquery Mobile,下面是调用webservice以返回json的代码 $('#page_job_list_pages').live('pageshow',function(){ try { $.ajax({ url: "http://domain.com/json/" + encodeURIComponent(tid), type: 'get', dataType: 'json', error: func
$('#page_job_list_pages').live('pageshow',function(){
try {
$.ajax({
url: "http://domain.com/json/" + encodeURIComponent(tid),
type: 'get',
dataType: 'json',
error: function (XMLHttpRequest, textStatus, errorThrown) {
alert('page_job_list_pages - failed to retrieve pages');
console.log(JSON.stringify(XMLHttpRequest));
console.log(JSON.stringify(textStatus));
console.log(JSON.stringify(errorThrown));
},
success: function (data) {
$("#page_job_list_pages_list").html("");
$.each(data.nodes,function (node_index,node_value) {
console.log(JSON.stringify(node_value));
if(node_index != 0) {
var companyName = node_value.node.field_basic_info.match("Company:(.*)date");
$("#page_job_list_pages_list").append($("<li></li>",{"html":"<a href='#node_view' id='" + node_value.node.Nid + "' class='page_job_list_pages_list_title'>" + companyName[1] + "</a>"}));
}
});
$("#page_job_list_pages_list").listview("destroy").listview();
$("#page_job_list_pages_list").append('<a onclick="()" data-role="button" data-theme="a">TEST</a>');
}
});
}
catch (error) { alert("page_job_list_pages_list - " + error); }
});
this line is a button
$("#page_job_list_pages_list").append('<a onclick="()" data-role="button" data-theme="a">TEST</a>');
$('page#u job_list_pages').live('pageshow',function()){
试一试{
$.ajax({
url:“http://domain.com/json/“+tid组件,
键入:“get”,
数据类型:“json”,
错误:函数(XMLHttpRequest、textStatus、errorshown){
警报(“页面\作业\列表\页面-检索页面失败”);
log(JSON.stringify(XMLHttpRequest));
log(JSON.stringify(textStatus));
log(JSON.stringify(error抛出));
},
成功:功能(数据){
$(“#页面#作业#列表#页面#列表”).html(“”);
$.each(数据.节点,函数(节点索引,节点值){
log(JSON.stringify(node_值));
如果(节点索引!=0){
var companyName=node_value.node.field_basic_info.match(“公司:(*)日期”);
$(“#页面(作业)列表(页面)列表”)。追加($(“”,{“html”:“}”);
}
});
$(“页面作业列表页面列表”).listview(“销毁”).listview();
$(“#页面#作业#列表#页面#列表”).append('TEST');
}
});
}
捕获(错误){alert(“页面作业列表页面列表-”+错误)}
});
这行是一个按钮
$(“#页面#作业#列表#页面#列表”).append('TEST');
我想调用jquery函数再次查询json
如何做到这一点?我已将您的查询包装在一个函数中。我想这就是你想要的。我还将调用添加到按钮的单击处理程序中,以便再次查询 注: 从jQuery1.7开始,不推荐使用
.live()
方法。使用.on()
附加事件处理程序。较旧版本的jQuery用户应优先使用.delegate(),而不是.live()。(来源:)
$('page#u job_list_pages').live('pageshow',function()){
queryJSON();
});
函数queryJSON(){
试一试{
$.ajax({
url:“http://domain.com/json/“+tid组件,
键入:“get”,
数据类型:“json”,
错误:函数(XMLHttpRequest、textStatus、errorshown){
警报(“页面\作业\列表\页面-检索页面失败”);
log(JSON.stringify(XMLHttpRequest));
log(JSON.stringify(textStatus));
log(JSON.stringify(error抛出));
},
成功:功能(数据){
$(“#页面#作业#列表#页面#列表”).html(“”);
$.each(数据.节点,函数(节点索引,节点值){
log(JSON.stringify(node_值));
如果(节点索引!=0){
var companyName=node_value.node.field_basic_info.match(“公司:(*)日期”);
$(“#页面(作业)列表(页面)列表”)。追加($(“”,{“html”:“}”);
}
});
$(“页面作业列表页面列表”).listview(“销毁”).listview();
$(“#页面#作业#列表#页面#列表”).append('TEST');
}
});
}
捕获(错误){alert(“页面作业列表页面列表-”+错误)}
}
这行是一个按钮
$(“#页面#作业#列表#页面#列表”).append('TEST');
你想让它现在做什么?我不确定你的问题是否具有必要的描述性。在pageshow
上运行该方法后,是否要再次运行该方法?单击按钮后再次运行该方法请参阅我在下面添加的代码。
$('#page_job_list_pages').live('pageshow',function(){
queryJSON();
});
function queryJSON(){
try {
$.ajax({
url: "http://domain.com/json/" + encodeURIComponent(tid),
type: 'get',
dataType: 'json',
error: function (XMLHttpRequest, textStatus, errorThrown) {
alert('page_job_list_pages - failed to retrieve pages');
console.log(JSON.stringify(XMLHttpRequest));
console.log(JSON.stringify(textStatus));
console.log(JSON.stringify(errorThrown));
},
success: function (data) {
$("#page_job_list_pages_list").html("");
$.each(data.nodes,function (node_index,node_value) {
console.log(JSON.stringify(node_value));
if(node_index != 0) {
var companyName = node_value.node.field_basic_info.match("Company:(.*)date");
$("#page_job_list_pages_list").append($("<li></li>",{"html":"<a href='#node_view' id='" + node_value.node.Nid + "' class='page_job_list_pages_list_title'>" + companyName[1] + "</a>"}));
}
});
$("#page_job_list_pages_list").listview("destroy").listview();
$("#page_job_list_pages_list").append('<a onclick="queryJSON();" data-role="button" data-theme="a">TEST</a>');
}
});
}
catch (error) { alert("page_job_list_pages_list - " + error); }
}
this line is a button
$("#page_job_list_pages_list").append('<a onclick="queryJSON();" data-role="button" data-theme="a">TEST</a>');