科尔多瓦和快递js? [英] Cordova and express js?

查看:51
本文介绍了科尔多瓦和快递js?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当客户端是cordova应用程序时,在客户端上呈现快速视图时我真的迷失了.

I am really lost when it comes to rendering express views onto the client, when the client is a cordova app.

有一些显而易见的事情,例如,应用程序将需要发出GET请求,而快速应用程序将呈现视图.

There are a few obvious things, for example the app would need to make a GET request and the express app would render the view.

我不确定该怎么做,一个人如何发出这些请求?

I'm not sure how to do that though, how does one make those requests?

在模拟器中,我尝试了 alert(window.location.pathname),它显示了 android_asset/www/index.html ,因此需要正确调整吗?

In the emulator I tried alert(window.location.pathname) and it shows android_asset/www/index.html so that needs to be adjusted right?

推荐答案

使用AJAX进行从应用程序到服务器的调用.这可以用纯JavaScript来完成,也可以通过jQuery之类的库或AngularJS之类的框架轻松完成.

Use AJAX to make calls from your application to your server. This can be done in pure JavaScript or easily with libraries like jQuery or frameworks like AngularJS.

使用纯JS的Ex:

var xmlhttp=new XMLHttpRequest();
xmlhttp.open("GET","my/route",true);
xmlhttp.send();

并使用

xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("aDiv").innerHTML=xmlhttp.responseText;
    }
  }

或者使用jQuery:

Or with jQuery :

$.get( "my/route", function( data ) {  $( ".aDiv" ).html( data ); });

但是,通常,在Cordova应用程序中,视图存储在客户端,并且仅通过AJAX请求获取数据以加速应用程序.

However, usually, on Cordova apps, views are stored on the client side, and only data are being fetched through AJAX requests to speed up the app.

这篇关于科尔多瓦和快递js?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆