2013-10-09 5 views
2

내부 JSON 내가 다시 JSON을 조회 할 JQuery와 함수를 호출 할는 함수 자체 여기

$('#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>'); 

에게 반환하는 웹 서비스를 호출하는 코드 버튼에서 JQuery와 함수를 호출.

어떻게해야합니까?

+0

지금 무엇을하고 싶습니까? 귀하의 질문이 필요한만큼 구체적이지는 않습니다. 'pageshow'에서 실행 한 후에 메소드를 다시 실행 하시겠습니까? –

+0

버튼을 클릭 한 후 다시 실행하십시오. – hkguile

+0

아래에 추가 한 코드를 참조하십시오. –

답변

0

쿼리를 함수에 포함했습니다. 나는 이것이 당신이 원하는 것이라고 생각하고 있습니다. 또한 단추의 클릭 핸들러에 호출을 추가하여 다시 쿼리했습니다.

참고 : jQuery 1.7부터 .live() 메소드는 더 이상 사용되지 않습니다. .on()을 사용하여 이벤트 처리기를 연결하십시오. 이전 버전의 jQuery 사용자는 .live()보다 .delegate()를 우선 사용해야합니다. (출처 : http://api.jquery.com/live/)

$('#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>');