Currently I have a working javascript/jquery file that makes a request to a php file to retrieve json data. This works great.
Some information is taken from the server and send back to the javascript/jquery.
So:
Request from js to exchange.php ==>
exchange.php access database and gets certain data
<=== response from exchange.php to jquery to send data to js
js uses data to make some changes to the website (changes phonenumber)
This has to be done as fast as possible. But after I have send the data to the js I want the same exchange.php log this data + some userdata to another database. For speed reasons I want to do this after the data is sent to the javascript. Is this possible?
Currently I just call the logging class after I echo'd json_encode(); But does it make a difference? Or will the json be send only after the whole php file has finished running?
Related
$.getJSON let us to get data from the file, is there any way to set data into the file? i have tried $.setJSON, but it shows me "$.setJSON is not a function".
You can't access the local file system using front-end Javascript. And there is no way on doing it.
What you can do is create a web server.
Send a request with the data in the server using AJAX
On the server, save the data by writing it on a file
That's pretty much it.
I am trying to write my first chrome extension. The workflow goes something like this -When the extension is installed and active if a user hovers over a specific product/ID displayed on the page, the extension retrieves related vendor data about the product with the ID.
This is how I thought about this:
Use jQuery attr to access the ID on mouse over.
Post this ID to a retrieve.php file with .post() method
The retrieve.php file retrieves the data from database
Display the data in a tool tip on the web page.
I have some queries for the above process:
I am able to get this working on a local XAMPP server but how will it work online as the chrome extension will not have access to server. What is the way around to retrieve data without using PHP?
I am able to get the logic working but am unable to place these in respective files - Will all my logic reside in background.js ?
Any suggestions on getting this started will be much appreciated.
You could build a very simple API on your server that responds with JSON to any request it receives after processing it. Like this:
{"firstVar":"foo","secondVar":"bar" }
Your chrome extension can then make an xmlhttp request to this server and and process the returned data.(You could also use JSONP and wrap the response in a callback function which will execute as soon as you have the reponse)
The JS extension will be able to deal with the JSON nicely as it can understand that format so you can then choose to display the data in whatever way you want.
Essentially, what you want is a server that can take an ID posted to it and return the corresponding date in a nice and readable format. And a chrome extension that can make an request to a server and then process the response. Build and test them separately (keep positing an ID to the server and see the response and for your JS side at first instead of making requests to your unfinished API just set a static response to begin with which will be the same as an expected response.
I have the below requirement.
I have a data grid, which has huge amount of data. I have a download button, when clicked data grid data has to be downloaded to an excel. This data grid data I want to send to server through a rest call using xhrpost. With this data i will construct an excel file on the fly on server side and i will return the response to the client. My client by seeing this response should open popup for downloading the response to save as the file.
I am seeing the following problems here :
the data is huge. so , I can't use window.open way for sending the data in GET format.
I don't have an URL on server which will access file, as i am generating file on the fly and sending response to client.
How will i achieve my use case to download file using xhrpost on the fly, not storing the file anywhere?
Please reply as I am breaking my head how to do this? It will be of great help.
Thanks,
Sreenivas
I'm posting json to my server and I want to return a csv response and have my browser automatically download the csv.
I know there have been some questions on SO exactly about this topic on the past. So far, I've gathered the following solutions:
Put the request into <form> element. This isn't possible because the JSON is nested and too large to be posted as a string.
Save the csv file (get request) onto the server and then have a separate post request to download it. This is not ideal because I don't want to keep a bunch of useless csv files on my server.
Is there a better solution? Can I make a Post request act like a form submission and automatically get the file to start downloading?
I am trying to make an html app for local use, consisting of an HTML page using Google Maps API V3, a SQLite database, and a SimpleHTTPServer script.
The workflow is the following:
User starts the server and opens the page, which contains a map with a set of markers, and a form with filters similar to those of Google Fusion Tables;
User interacts with form, which sets some parameters for a query;
When the user clicks "Submit", page sends a request to HTTPServer, whose request handler queries the SQLite database and returns the result as JSON/JSONP/something-else;
Some function takes back the data and map is updated;
My doubts are more conceptual than anything else, and specifically I would like to know (how/where to look for):
How should I send a request for the server in javascript, and how to listen back to it?
How should the server send data to the request, in order to update its value instead of refreshing the page?
Sorry if my questions seem obvious, but HTTP is something very new to me, and so is client-server communication.
Thanks for reading!
I think you can use CGIHTTPServer.
ref:
http://pydoc.org/2.5.1/CGIHTTPServer.html
Q:How should I send a request for the server in javascript, and how to listen back to it
A:Please google "ajax". "jquery" is one of the most convenient javascript library for ajax.
Q:How should the server send data to the request
A:just use "print" in python script which is called by CGIHTTPServer.
In this case, the output of "print" will be the response to http client(web browser).
In the script mentioned above, you should extract request parameter sent by http client,
with "do_Get()" or do_Post() function.