2013-03-24 53 views
1

典型案例:如何在通過Ajax加載的文件內容上使用xpath?

 $.ajax({ 
      url: schedule.link, 
      context: document.body 
     }).done(function(data) { 
      // tutt ok, quindi scrivo il file 
      console.log (data); 
     }).error(function (jqXHR, textStatus, errorDescription) { 
      // segnalo il problema 
      logga("Error " + error.description); 
     }); 

如何使用上data XPATH通過AJAX收到?

我需要簡單地得到//ul.result作爲XPath的

+0

你可以使用document.evaluate https://開頭開發商.mozilla.org/en-US/docs/Introduction_to_using_XPath_in_JavaScript – Vortex 2013-03-24 17:31:12

+0

請給我一個例子... – realtebo 2013-03-25 11:06:00

回答

1

你必須做如下(如果你使用jQuery):

$.ajax({ 
     url: schedule.link, 
     context: document.body 
    }).success(function(data) { 
     // gives you the html inside the matching expression 
     alert($('xpathexpr', data).html()); 
    }).error(function (jqXHR, textStatus, errorDescription) { 
     // segnalo il problema 
     logga("Error " + error.description); 
    });