HTML 5 Web Storage - Local/server communication - ajax

I need load localStorage data right on my homepage. But when the page loads, the PHP/SQL instructions are already processed.
There's a way to process it before the server interation and use the localStorage data in my SQL instructions?
ps. I tried AJAX, loading my homepage in a DIV inside an index page... but it didn't work.

The answer is no - you can't read the LocalStorage data on the first load of your web site. However, you can use Ajax to hit your server and send a copy of any LocalStorage value to your server. You mentioned using ajax to load your homepage in a div. That should work, if you pass along the LocalStorage information in the url. So for example, imagine you have a localstorage key called name. If you want to load the contents of foo.php into a div and have PHP get access to name, you would pass it in the URL: "foo.php?name="+escape(localstorage.name)". You can also use a Form post too.

Related

How to load view containing data with ajax?

I have Restful controller that renders a view with data from database and I want to load this view with its data in another view via ajax. There is a problem "undefined variable". Is there any solution?
When you pass variables to your view they are only available on the server side while the view renders and then they are discarded. What this means is that the variables are only available to the php of your application and then they are gone by the time the view has been rendered and sent to the visitors web browser.
If you try to use the variables with JavaScript then you are running the JavaScript on the client side (as opposed to the server side). The variables that you pass to your view do not exist on the client side where your JavaScript runs.
From what it sounds like. You are defining a variable in your controller via laravel. Then you are passing the variable from the controller to the view. The view is then rendered as html and sent to the visitor's computer (the client) which the html is then loaded and that is when the JavaScript starts to load.
That's the problem, now possible solutions.
First you could send the variable (assuming it is simple data and not like an object) to the browser through laravel flash variables which are actually stored on one time cookies on the client side. Then you use JavaScript to access the cookie and get the data then storing it to a js variable and using it in your script.
Second you create an Api to respond to your http requests and then send an Ajax request from your JavaScript to the api to get the data. Then you would store it in JavaScript and use it. This allows complex data like objects because you would use the JSON format to send information to respond to the Ajax call. While cookies are restricted to (5kb I think) there is really no theoretical limit to JSON data.
I hope that helps and I hope I'm understanding your problem.
Would need to see your javascript before anything, but usually for me this means a misspelled element id or misspelled a reference file

Pre-populate Ember DS.Store via ajax

Reading the Ember guide about the data store it's not clear how you pre-populate the store with your data. I see you can set up the RESTadapter with the host name, and the 'store.find' method will trigger a 'get' request if the data is not cached, but how can I initialize a DS.Store with JSON data via ajax before ever doing a find?
Ember guide model HTTP
The context for this is, a single page app that on page load gets a blob of json, which is used to model out the rest of the site. The end result gives the illusion that the site contains multiple pages.
Sounds like you want this.store.pushPayload(..)
http://emberjs.com/api/data/classes/DS.Store.html#method_pushPayload
Note that you only have access to the store inside Routes and Controllers. Consider putting this inside the activate hook of App.ApplicationRoute
http://emberjs.com/guides/routing/defining-your-routes/#toc_initial-routes
http://emberjs.com/api/classes/Ember.Route.html#method_activate

How to load an entire HTML page from one website into another

I have been working on a website www.xyz.com which is hosted on some server. I have been loading forms & contents from www.abc.com using I Frame which is hosted on Azure. We have now decided not to use I Frames and to load the content from www.abc.com using Jquery AJAX. Now the abc.com is providing me the UI page fragment for my forms and contents from Azure blob storage in form of .html file or .txt file. If i try to do a normal AJAX call for the HTML or TXT file path, i can the see the content coming in the Response tab of that URL but the code does not enters the Success template and hence i am unable to modify or access the content.
Please suggest
You can use Application Request Routing (ARR) for this. This is a module you can install in IIS which also works in Windows Azure.
The following image illustrates how ARR works. An incoming request is intercepted and based on a set of rules the request is forwarded (for you this will be to xyz.com) and the response is the served back to the user. Even though this illustration explains the principle with sub directories, it can also be applied on the full site.

Delphi: Log the GET request URLs used in Websites that are updating content via AJAX (TWebbrowser)

Using a TWebBrowser in Delphi, I'm showing a website that uses JSON to update its content. To get the source code of the newly updated content and load it into a Memo, I believe I have to get the URLs of the GET requests. Unfortunately, these are always different and generated with an encrypted Javascript. Is there any way to list the URLs the GET requests go to in a similar way like FireBug does in its console view?
Thanks a bunch!!!

Cache web forms in client side

is it possible to cache form contents on client side? Like maintaining state even if the form is un-saved and the user moves to a new page then returns back to the form?
The best way to do this would be by using Javascript/AJAX to talk to the server, saving each form field as the user went off it. Then, when you load the page, you'd see if there was any content for each form already saved.

Resources