I am curious if this is possible:
on the website:
using jquery to get value from a html tag and store the value as a variable
using ajax to call a file (xml, html or txt) on servside or external site for a php file
define the current value in the xml html or txt file
and add this value to the current value. = new value
store this new value in the xml html or txt (saving the file on server...)
Q1. Is this achievable?
Q2. If so, what file is best used/supported? (php would be my very last alternative option) I prefer xml and html...
Q3. step 1 to 4 i can get to work - but step 5 i have totally no experience in. Anyone can guide me the right direction for writing those documents?
You cannot write the file directly in the server using javascript.
What you can do, for example, is send the updated data to a page in the server (sending a request to a PHP page, or a MVC endpoint, or whatever server-side technology you want to use) and then have the server code update the file using that data.
You can do this with AJAX (eg. using jQuery with $.post) if you want it to happen in the background, or with a normal request (which will reload the page or take the user elsewhere depending on the server code).
Related
I am developing a web app which functions in a similar way to a search engine (except it's very specific and on a much smaller scale). When the user gives a query, I parse that query, and depending on what it is, proceed to carry out one of the following:
Grab data from an XML file located on another domain (ie: from www.example.com/rss/) which is essentially an RSS feed
Grab the HTML from an external web page, and proceed to parse it to locate text found in a certain div on that page
All the data is plain text, save for a couple of specific queries which will return images. This data will be displayed without requiring a page refresh/redirect.
I understand that there is the same domain policy which prevents me from using Javascript/Ajax to grab this data. An option is to use PHP to do this, but my main concern is the server load.
So my concerns are:
Are there any workarounds to obtain this data client-side instead of server-side?
If there are none, is the optimum solution in my case to: obtain the data via my server, pass it on to the client for parsing (with Javascript/Ajax) and then proceed to display it in the appropriate form?
If the above is my solution, all my server is doing with PHP is obtaining the data from the external domains. In the worst (best?) case scenario, let's say a thousand or so requests are being executed in a minute, is it efficient for my web server to be handling all those requests?
Once I have a clear idea of the flow of events it's much easier to begin.
Thanks.
I just finish a project to do the same request like your req.
My suggestion is:
use to files, [1] for frontend, make ajax call to sen back url; [2] receive ajax call, and get file content from url, then parse xml/html
in that way, it can avoid your php dead in some situation
for php, please look into [DomDocument] class, for parse xml/html, you also need [DOMXPath]
Please read: http://www.php.net/manual/en/class.domdocument.php
No matter what you do, I suggest you always archive the data in you local server.
So, the process become - search your local first, if not exist, then grab from remote also archive for - 24 hrs.
BTW, for your client-side parse idea, I suggest you do so. jQuery can handle both html and xml, for HTML you just need to filter all the js code before parse it.
So the idea become :
ajax call local service
local php grab xm/html (but no parsing)
archive to local
send filter html/xml to frontend, let jQuery to parse it.
HTML is similar to XML. I would suggest grabbing the page as HTML and traversing through it with an XML reader as XML.
My web application uses file which has been updated by other process. My application reads the content of the file using ajax
xmlhttp.open("GET","/config/myfile",false);
xmlhttp.send();
Once response is received then app parses this response and shows that values on Web UI. The file contains 50 fields and whenever I want to read any single field I need to open whole file.
Is there any way to get the values of single field based on key instead of reading whole file.
As per my understanding we need to read and open file and then parse the response text. But would like to know is there any way to reduce the file calls with any other method.
I want to achieve this to reduce the file I/O operations. Since other processes are writing in to it and at same time my web app accessing to read the latest value.
Any other option would be appreciated.
Note :- I do not have to use any server side scripting lang option.
Regds
In a web project using jsp, I have following requirement
Upload a file (say an image) to a different domain, which returns an xml that includes details of uploaded file (eg: path of uploaded image etc).
How do I capture this xml to save details in db?
I cannot do a normal html form submit, since I lose control after that. So I tried to implement this by setting form target to an iframe. But I cannot process contents of iframe?
Any suggestions how I can accomplish this?
Can I process this using yql?
Yes, you can do this using YQL. Not easy though, and you'll need to set up your own YQL table.
Each YQL table is a XML file describing how to operate on data. The YQL XML specification allows you to define an <execute> element that you can use to write JavaScript code that does almost anything.
Inside this <execute> block, you can use the y.rest object to POST data somewhere else.
You'll probably have to encode the file using base64 to be able to actually POST data using the YQL syntax, something like INSERT INTO mywebsite.files (name, data) VALUES ('foo.png', 'KBB987987JJBHBGV==') (second param is a illustrative base64-encoded file).
Assuming the server you are submitting the file to is not under your control (so you can't use CORS), you have proxy the request through your own server.
You can't use YQL as you can't make post requests with it.
I am making a website but I get a bit lost programming dynamic sites.
The user needs to enter x (inside a textbox), click submit, process in java (serverside) and present outcome as a report to the user (using javascript).
I'm at the moment using JSP to process the users input but now I need to pass the JSON code into the javascript. The javascript requires JSON data.
At the moment I have JSP which returns the necessary JSON code and the Javascript which works with hardcoded JSON code. I need to somehow store the returned JSON (from the JSP) in a variable and pass it to the Javascript. I have a vague understanding of AJAX - i'm just unsure if this is possible and how to link it all together.
Thank you.
Your JSP "page" can simply generate JSON directly. There's no reason the output from JSP has to be HTML. From the client, therefore, you POST to the server, the JSP runs, and the result (pure JSON from your JSP) is sent back to the client as the ajax response.
Sounds like the perfect place for AJAX - you can submit the request with javascript, and when it comes back process it further with javascript. Unless you want the page to refresh.
If you are using jQuery, you can look here to see how to implement it, should be relatively painless: http://api.jquery.com/jQuery.post/
Is it possible to get temporary filename with javascript?
I want upload a file using ajax... So, i want to get the tmp filename with js. Is this possible?
AJAX itself won't let you upload a file via a web form - you need to perform a traditional form post to a window (or a frame/iframe) in order to send binary content. Such a post must be handled by your server code (in Java, PHP, python, etc), which can process the stream into a temporary file (some languages/frameworks such as PHP can do this automatically).
You can then make the temporary file available via a URL scheme, and return this URL back as the result page of the post. If this is all on the same domain as your main page, you can then use Javascript to look "inside" the result iframe to find the temporary URL.
If your using AJAX in combination with your server side language just return the temporary name and pull it in with the AJAX, if can all be done in 1 call.