从phonegap的外部网站获取数据

时间:2013-08-27 14:45:40

标签: javascript jquery html5 cordova

我必须使用phonegap(HTML5,css,javascript,json,jquery,...)开发应用程序。 此应用程序必须打开外部网站(使用inAppBrowser)才能登录,然后返回提供令牌的应用程序。 现在我可以打开外部网站,但我不知道如何回到应用程序。 有人能帮我吗? 感谢

奥马

2 个答案:

答案 0 :(得分:1)

我只是粗略地编写了一些代码来从外部网站检索数据。希望这会有所帮助:

var yourApp = {
getData : function(q) {

var search_url = "http://xyz.com/xyz/customfeed?filterby=custom&urlfilter=1&" + q;
$("#loading").show();
$.ajax({
  type: 'GET',
  url: search_url,
  dataType: 'xml',
  success: function(xml) {
    $('entry', xml).each(function() {

      var hi = new xyzDataItem();
      hi.title = $(this).find('title:eq(0)').text();
      hi.link = $(this).find('link:eq(0)').attr('href');
      hi.desc = $(this).find('summary:eq(0)').text();
      hi.date = $(this).find('updated:eq(0)').text();
      hi.id = $(this).find('id:eq(0)').text();
      $("#loading").hide();
          $("#search_results").append('<div class="abc">' +
          '<h2>' + hi.title + '</h2>' +
          '<P>' + hi.desc + '</p>' +
          '<P><a href="' + hi.link + '" class="external">xyzData</a></p>' +
          '</div>');
        });
    }
  });
}
}

答案 1 :(得分:0)

如果您使用的是InAppBrowser,请执行以下操作:

document.addEventListener("deviceready", onDeviceReady, false);

function onDeviceReady() {
     var ref = window.open('http://apache.org', '_blank', 'location=yes');
     ref.addEventListener('loadstop', function(event) { 
          if (event.url,indexOf("http://apache.org") > -1){
              //do something
          } 

     });
}

理想情况下,令牌应该是URL的一部分,以便更容易检索。否则使用$ .getJSON方法,不要使用InAppBrowser。但是如果使用InAppBrowser,则令牌应该是查询字符串参数。

E.g。 http://yoursite.com/loginsuccess?token=adsfsadfdsfasdf

相关问题