Reputation: 13422
I am really lost when it comes to rendering express views onto the client, when the client is a cordova app.
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?
In the emulator I tried alert(window.location.pathname)
and it shows android_asset/www/index.html
so that needs to be adjusted right?
Upvotes: 1
Views: 3779
Reputation: 1023
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.
Ex in pure JS:
var xmlhttp=new XMLHttpRequest();
xmlhttp.open("GET","my/route",true);
xmlhttp.send();
and fetch response with
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("aDiv").innerHTML=xmlhttp.responseText;
}
}
Or with jQuery :
$.get( "my/route", function( data ) { $( ".aDiv" ).html( data ); });
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.
Upvotes: 3