cross domain rest dojo call - json

I have to load data for a different url the page will run on the android browser and will load content from remote server .
I have to use dojo so I tried with dojo.xhrGet , it does'nt load the data so when I red the reference guide I saw that that method has some limitation with external url's .
So what I have to do now if I have to call a REST service with dojo .
the REST service URL on the remote server:
http://192.168.1.65:9080/RAD8JAX-RSWeb/jaxrs/customers/accounts/111-11-1111/
and the data that I should see
[{"id":"001-111001","balance":12345.67},{"id":"001-111002","balance":6543.21},{"id":"001-111003","balance":98.76}]
please help me with a method that can fix my problem I dont know dojo well I'm blocked right now because I can't use the data between two application they can't communicate

Your question is unclear, but I think you are saying you want to load data from a different domain to the main web page.
You cannot reliably use AJAX to load data from anywhere other than the domain of page you are visiting.
Almost all modern internet browsers deliberately block that, for the protection of their own users.
Instead, you will need to find some way of getting your server to relay the information.
So imagine currently you do:
Load page a.example.com/index.html
Page uses dojo to try to load b.example.com/data
You would instead need to do:
Load page a.example.com/index.html
Page uses dojo to try to load a.example.com/data
When the a.example.com server receives a request to load /data, it should connect (perhaps using cURL) to b.example.com/data and then output the same text.

Related

Http redirect for content on relative paths

Essentially what my use case is, a 3rd party server only support POST on a specific integration url. but I want a browser to hit it from a normal html link (I have no control over either systems code, I can only configure the destination url for the link)
To solve or this I have written a web hosted app (done in Mirth Connect - but the server tech in theory shouldn't matter). The objective of my app is to cat the GET and convert it to a POST
My systems logic:
My web server receives an HTTP GET from a browser, grabs the query strings.
The server then performs an HTTP POST on a 3rd party server, and grabs the html result
The server then returns the original html and delivers it as the result to the original http request from the browser
This works great, the issue comes in with content hosted on the 3rd party server that is referenced with a relative path (css, js, images, etc).
Because I have "tricked" the browser into thinking it received the html from my system, it looks on my server for the content (which will all 404).
Without having to handle the fetching of all the content myself, is there a way to tell a browser to redirect all further queries to the 3rd party server?
I tried making my HTTP GET return a status 301 or 302 with the location being the base address of the 3rd party server, but this obviously tells the browser to redirect completely
Figured it out.
I just had to intercept the html and inject a BASE tag .

web app on top of a REST API - how to persist data between page requests?

I'm starting with web development these days and I would prefer so called client side rendering. In practice that ajax request needed data and add them to the html file ( which has already the static content, and dynamic data is added via 2nd request ). I like this approach, cause of a clean seperation between client and server. You just need to define an API and you can seperate the work.
So if you don't create the dynamic content on server side, how dou you persist data between page requests.
For example, you are on a overview for a list of adresses. You can click a button to edit a specific adress with id "25". That will requiere a new html file for that task, which will be loaded and rendered. How does the javascript included in that html file know, which adress should be loaded. How can it access the id "25"?
Approach 1. You don't persist anything on the client and simply reload everything as you go back and forth between the list page and the editor page. Editor page gets the id "25" and loads corresponding item either using AJAX, as you want, or on the server.
Approach 2. You do everything on the same page (SPA). You use JavaScript and probably some framework like Angular to maintain your page state.

Geocodezip map empty sidebar

I am using the following example of a map in my webpage. (obtained from an answer in this other question) The source code of both is practically the same, but I can't make the titles of the locations in the sidebar to appear in the page hosted in the client server. (they can be viewed in the original page)
¿Do you know if here is any problem of compatibility or if I can add any extra code to make it work?
This is the example page:
http://www.geocodezip.com/geoxml3_test/v3_geoxml3_kmltest_linktoB.html?filename=http://www.geocodezip.com/xmlProxy060215.asp?https%3A%2F%2Fmaps.google.com%2Fmaps%2Fms%3Fhl%3Den%26ie%3DUTF8%26oe%3DUTF8%26authuser%3D0%26msa%3D0%26output%3Dkml%26msid%3D216330649072490208011.0004daf6e6bfde8dd857d
This is the page in the client server (I only removed the example buttons, but even with them the information is not showing):
http://www.vitrocar.com.mx/orchard/media/map.html?filename=http://www.geocodezip.com/xmlProxy060215.asp?https%3A%2F%2Fmaps.google.com%2Fmaps%2Fms%3Fhl%3Den%26ie%3DUTF8%26oe%3DUTF8%26authuser%3D0%26msa%3D0%26output%3Dkml%26msid%3D216330649072490208011.0004daf6e6bfde8dd857d
Using a proxy on my server:
http://www.geocodezip.com/xmlProxy060215.asp
Defeats the purpose and will not work. You need to have the proxy on your server.
The proxy is used to overcome the cross-domain restriction on XmlHttprequest (XmlHttpRequest is used by geoxml3 to access the remote KML, it can only access XML in the same domain as the website).

Displaying remote URL

First I must explain I am a total newbie with regards to web design.
My question is as follows:
I would like to have a remote URL displayed through a different web server. The remote URL resides on an internal firewalled server and I would like to give public access to a single page by displaying it on a remote web server that has access to the firewalled page. I have tried iframes but they use the clients IP which results in the page failing to display. I have limited access to the server (CPanel) - please advise how this is possible? The remote URL will be requiring a login - not sure if this will have relevance on the solution.
What you can do is create a page which makes a request to the firewalled page using either CURL or HttpWebRequest or any compatible technology based on the platform you have chosen. It can then trim out the headers and other tags which are not required and render the html in a div, or it can just redirect the entire code in the response of your page.
This way, there will be no connection made from the client end, just your server will connect to your firewalled server and fetch the page from there and in turn give it back.
The only problem here is, forms - images and linked objects might not work properly, you might also have to parse them and replace the respective urls to point to your server which in turn proxyfy it.
Here is an example of it
https://proxify.net/

Use the locally stored version of the page instead of another request

I'm workin' on a web project where performance is a very important issue.
EDIT:
The situation:
I wanna add some details about the user's workflow:
The user visits the welcome page of my website http://example.org/ .
He clicks a link in order to visit the page http://example.org/mypage
onclick-Handler of the link's executed.
The handler loads data usin' XHR.
The handler creates http://example.org/mypage dynamically.
The handler saves mypage locally usin' FileSystem API at filesystem:http://example.org/mypage. EDIT: ( filesystem:http://example.org/mypage is a local ressource stored in the FileSystem at the client side)
The handler extends the history and changes the URL of the location bar usin' History API from http://example.org/ (URL of the welcome page) to http://example.org/mypage (the page which the user wants to see) .
The user vists another page in the meantime.
Later on, the user types http://example.org/mypage directly into the location bar.
The browser shows/loads filesystem:http://example.org/mypage (which is the locally stored version of http://example.org/mypage) instead of http://example.org/mypage. That means: The browser doesn't create a new request, it uses the local stored copy of http://example.org/mypage .
How can I get the browser to use the locally stored version of the page instead of creating a new request? EDIT: - That's what I want to do in #10 of the list above.
EDIT:
My Question:
A client-side has already created/generated http://example.org/mypage in #2 to #7 of the list above. I don't need to create that page some other time. That's why I don't want the browser to create a request for http://example.org/mypage.
That's what I wanna do:
If filesystem:http://example.org/mypage has already been created (respectively if the user has already visited http://example.org/mypage):
Use filesystem:http://example.org/mypage instead of http://example.org/mypage.
Otherwise:
Send a request for http://example.org/mypage
Tries to solve:
I can't use the Fallback section of the manifest file to do something like: EDIT: (aside from the orgin)
FALLBACK:
http://example.org/mypage filesystem:http://example.org/mypage
In order to get the browser to use the local version stored in the FileSystem because Fallback directives are just used if the user is offline, otherwise they are ignored. EDIT: But I want to use filesystem:http://example.org/mypage instead of http://example.org/mypage, even if the user's online.
I know that I can use the Expire field in the response header of a server-generated page in order to not create a new request and to use the cached version.
But what if I create an page dynamically on the client side using JS and XHRs. EDIT: (I described that case in The situation) When create a page at the client side there's no way to get the client to cache that page. That's why I "cache" the page manually usin' FileSystem API to store it on the client side.
In order to improve the performance I'm trying to store any page which the user has already visited locally. When the user visits a page again then I show him the old, locally stored version of the page and my script creates an XHR to find out if the page changed in the meantime.
But how can I get the browser to use the local version of the page?
I can save the generated page locally on the client side using the FileSystem API and I can choose an URL for the generated page to display it at the browser's location bar using the History API.
When the user now visits another site and then presses the back button I can catch the onPopState event by an event handler.
And that event handler can load the dynamically created file using the FileSystem API.
But what should I do if the user doesn't use the back button and if he types the URL, which I have registered using the History API, directly into the location bar?
Then the browser wouldn't use the locally stored version of the page, the browser would create a request to load the page from the server.
Don't put dynamic data in the application cache. If you want to put dynamic data in your pages then get it from the server with AJAX, store the data in Local Storage, and populate the page with the data from storage through JavaScript (you can hook into the History API for this).
By the way, this won't work because fallback entries have to be on the same domain:
FALLBACK:
http://example.org/mypage filesystem:http://example.org/mypage
Once your page is in the Application Cache (ie. it is locally stored) the browser will always use the version from the Application Cache until the manifest is updated or the user deletes the cache. It doesn't really matter what expiry headers you put on the page, except if you put a long expiry and you frequently update the manifest then it's likely the Application Cache will be populated from the browser cache rather than refreshed from the server. This is why the stuff you put in the Application Cache should be static files. Get your dynamic stuff with AJAX.
You might use URLs that encode the actual link within your hierarchy, e.g. "mypage", in the anchor part of the URL, i.e. http://example.com/#mypage. Then you can use window.location.hash to obtain the string after the # and do whatever magic you want. Just make sure your root (or whatever you want in front of the #) is in AppCache.