Save form data via ajax with no server code - javascript

I am looking for a way to save simple form data from a static web page without any server-side code. I've considered something like MongoLab via RESTful interface, but that would require including API credentials client-side and the saved data must be private. Any suggestions? Thanks.

you need to post you form data somewhere, so you must have a server listening for a http form submit, or alternatively use something like socket.io / WebSockets to send all the data to a server. You cannot write to a database from a user browser without contacting some server that will write the information to the database..

Hadn't thought of using a BaaS (back-end-as-a-service) provider like parse or stackmob, but that's the solution. Just hadn't thought of using it for a simple, static web page. I signed up for parse.com and was collecting data within five minutes!

Related

How to send data from an Electron.js app to a remote server/db

As the title states, I'm having trouble finding a way to send data from an electron.js app to a remote db/server.
I can use mysql to connect directly with a database but it doesn't strike me as a secure thing to do. I would like to send the data, probably a json string, to a php or js file on a server and handle the validation and database access there.
I'm very new to working with node.js and electron.js but I'm really excited over the possibilities of it.
Have you got a working web server?
I'd recommend express - it's fairly simple to get started. You could define a route that you could post your data to, and then that would in turn add it to the database.
You can make a standard AJAX request from the browserWindow of your Electron app. Please refer to this question:
javascript ajax request without framework

Share PHP session with Javascript

I have a PHP app that renders HTML pages for a social media application that I'm creating. Then, JavaScript initializes and makes things interactive. The PHP side of things logs into a separate webservice with curl.
Now, I can't figure out a way to share the session started in PHP with JavaScript, so when I make a AJAX request in JavaScript to the data server, its authenticated.
Is there a way to share a PHP session with JavaScript? Or to share authentication initially created with PHP with JavaScript?
I would say it sounds like there is something wrong with your architecture. In my opinion, the web server itself, should be the only peer providing data to the client/browser. It's a two party conversation only.
When trying to hit a third-party server from the browser, you violate the browsers Same-Origin Policy, unless you specifically allow CORS by explicitly setting various request and response headers. - and you would only do so in very special situations.
The best solution might be to create proxy services at the web server, that can be hit directly (locally) by the browser. The web server can then (acting as controller) forward the data-request to the data server (model) and finally return the response to the browser (view).
You can read out the session cookie set by PHP (SID I guess) through JavaScript containing the session ID.
When you make a query, use
http://example.com/?sid=SessionID

How to secure JSON calls of a HTML5 App to a Server

I'm currently planning to develop a HTML5 app. The basic concept is the following:
A user should be able to create a profile with username and password. The Server should be implemented in Ruby on Rails providing a JSONP Api (for Cross-Domain issues).
So the App will send Ajax requests to the Server and get responses from it.
My idea was now to transmit a session_key (generated by server) on the first response back to the client. Then the client has to authenticate himself with this token.
But now i have some issues.
How can i secure the first call of the client (when he is transmitting user and password)?
How can i protect the Session-key from beeing spyed out?
I am a complety noob in security aspects. Therefore it would be great if i could get some hints where to look at.
Secure your connection with SSL. This should require no changes in your code apart from putting 's' after 'http' ;-).
I used add a checksum to the ajax parameters (calculated using the submitted data), and then to crypt the hole ajax request into one string.
Somthing like sRequest=459fdjnfdw4r908vn....
sRequests holds my data (sUser=user&sPass=pass&iCheck=34564).
Edit: My client code was not public, compiled to an app.

How to Replicate Web Form Call With WinJS.xhr

I'm working on a Windows 8 app, building it in HTML5/JavaScript. Part of the functionality in the app requires user authentication. The process in place is via a web form that posts the data back to a server side script and, upon successful authentication, returns a set of cookies. The data in these cookies can then be cached and used to perform several other API calls. I would like to use WinJS.xhr to do this instead of embedding the web page in the app.
First, I assume I can use the data parameter of the xhr method to pass the username and password information to the server-side script, but I'm not sure how to format that for a POST.
Second, if I can get the authentication piece to work, is there a way for me to see the cookie content returned in the HTTP response header?
You should be able to encode using the FORM encoding standard. I have some sample code that is intertwined in here, but it's very simple to encode it, and set the method to "POST" rather than GET.
For cookie transfer, you should be able to pull those out of the headers and set them as appropriate.

Calling client javascript with params from server side in ASP.net

I have an ASP.net webpage, that periodically (once in a minute) makes a call to my WCF REST service. My REST service responses some XML data. After getting it I make some further operations on that on server side in my ASP page.Note, this post data process in ASP is required, I can't avoid it. I know my life would be easier without this step, but I must do it.
After I'd like to pass this data in XML format to a client side javascript, that can parse it and show infos to the user based on this data. How can make this call from server side? What is the best pattern/practice to do it?
.net4/VS2010
if you want to call a function that already exists, that will load your data to the screen, you can tell the server to return your data and then ajax will grab that data and call a callback function.
if you are not using ajax, you can reload the whole page with the new data.
HTTP is not designed to push data from the server to the client. I'm not really familiar with ASP but usually you have the following possibilities to "push" data to a client javascript application via HTTP:
page reload via meta refresh (which doesn't actually push data;) )
periodically polling an "job queue" URL using javascript
comet (see http://en.wikipedia.org/wiki/Comet_(programming)) for an overview)
Web Sockets (which actually pushes data to the client but is only supported by newer browsers)
I've been using atmosphere (http://atmosphere.java.net/) which works pretty well in java application containers, which provides an abstraction layer over the underlying technology. I don't know if there is something similar out there in the ASP-world.
cheers
Martin
Tom, in that case just do the following

Categories

Resources