I am making a webpage which, largely, aims to submit a form to another webpage, process the results further, and display them on browser.
[1] Input form is ready. The form data is to be submitted to http://toolkit.tuebingen.mpg.de/hhpred/
[2] After the form is submitted, my webpage is redirected to the "Waiting" page of that website.
How do I stop this redirect? I cannot use AJAX, because it cannot work between different domains. (Can I ?)
Further, I need to get the response data and process it.
A possible solution can be: a PHP script, which should work as:
form-->submitted to my server-->submitted from my server to http: //toolkit ... -->response received by server --> processed further -->diplayed on browser
Currently I have created the webpage with flask. I have also used flask for "process further part".
My Question is: How can this process be acheived?
If I use PHP, how to integrate it with Flask?
Maybe you can use this: http://api.jquery.com/jQuery.ajax/ which supports crossdomain requests...at least in a way
Related
I have previously used PHP CURL to submit web forms by using the post URL.
I'm trying to automate the process of logging into a website, I can't change server side code.
The submit button on the HTML form uses the action of javaScript:submitForm() how can I submit information to this form using PHP.
Is CURL still an option?
Thanks!
You'll need to find the function declaration for submitForm and see where it is posting to. Then you can use php and curl to submit.
Edit:
Since the submitForm function doesn't change the form action, you can still use the action in the form tag.
Regardless of how client-side code is crafting the form submit, it still needs to send an HTTP request to the server. If you can do this manually by interacting with the site in question, then capture that request using browser debugging tools (FireBug, Chrome dev tools, etc.). That should have all of the information needed to craft a custom request of your own.
Note, however, that the website in question might have measures in place to prevent something like this. Especially if they're using a framework that handles the form posts for them (such as ASP.NET WebForms or anything like that). They may be emitting a form field to the page which contains a one-time-use token to be validated in the subsequent form submit request. If that's the case, any time you want to craft an automated form submit you'll first need to craft an automated request to parse out that token so you can use it in your submit.
If they take even more involved measures to prevent what you're doing, then you're going to have more of an uphill battle automating it.
Context:
There is an asp page in another web site that contains a search form. After submitting this form with the search value, the page displays the results of the search in an iframe.
Question:
I want to use the returned result in my page without loading that page in browser. I have got permission from the other web site administrator. I know php and jQuery. How should I proceed?
Example:
abcd.asp contains a form which contains <input name="regno"/> and a submit button. The form submits to itself and results Name, date of birth and Marks is returned in table format in an iframe.
Notes:
I have a page with same <input> and upon submitting it will use the above asp page and get details and display it in my page.
Easiest way:
Use jQuery to submit your page via AJAX to a local PHP file.
When the local PHP file gets the request, do a curl post request to your remote page and fetch the results.
Return these results in your local PHP script so that these will be available to your AJAX request
Your ajax request now has the remote contents, so just use jQuery to push them into the document.
You should use AJAX to perform this task. It loads a particular section of data without reloading a page. More info about what is ajax is here
Your best option is to use jQuery's ajax method. To make this work with different domains you need to enable crossdomain support. This is very easy in jQuery:
$.support.cors = true; // enable cross domain support
Now you can make a request to another domain. Of course the server on that domain must also accept cross-domain requests. ;)
Option 1 - HTTP GET & JSONP
As Twisted1919 pointed out you have to use jsonp if you want to make a HTTP GET request. If you're not familiar with jsonp It requires a bit of reading to understand the concept. But there is excellent support for this in jQuery (as described in jQuery.ajax()).
Option 2 - HTTP POST
If you're using http post to make your request you can simply use jQuery.post() for this. With cros domain enabled an the server accepting your request this should work out of the box.
I m trying to make messenger kind of service. In which I am facing a problem. I am supposed to reload the page manually. But the problem in running it automatically is that it gets reloaded for every second. I had used a javascript for reloading the page for every 1 sec. Inside which i m calling a php script. But the problem with that code is that complete page gets refreshed. Is there a way to reload only a particular part of the whole page and also i should be able run the php script in the background.
Use Ajax. Basic w3schools tutorial
Ajax is a group of interrelated web development techniques used on the client-side to create asynchronous web applications. With Ajax, web applications can send data to, and retrieve data from, a server asynchronously (in the background) without interfering with the display and behavior of the existing page. Data can be retrieved using the XMLHttpRequest object. Despite the name, the use of XML is not required (JSON is often used instead), and the requests do not need to be asynchronous.
[Wikipedia]
My problem is:
I have mobile application using jquery+jquery mobile+phonegap. In this app I have several pages with forms. I want to submit this forms to remote server where is php file for handling variables and it return simple text as output. My big problem is that I don't know how get this data in my application without redirecting to Android browser. I search over internet and I can't find how figure it out
This sounds like you should be making an ajax request from jquery to the php file that handles the request and will return the appropriate response. Take a look at the jquery documentation to see how to make an ajax request, where the url field is the url of the php file and the data field is the variables you want to pass to the php file.
http://api.jquery.com/jQuery.ajax/
So I am very new to this concept.
So why not go headfirst :) Some things I don't understand;
What happens if js is disabled?
If using mysql databases (ie; checking forms and such) why not just use php?
To confirm what others have said, disabling Javascript will also disable the AJAX call. After all, AJAX stands for "Asynchronous Javascript and XML".
To address why you can't just use PHP, there are some things that just can't be done without it. PHP is great to load the page with the initial information, but after the page is loaded, it actually requires the page to be reloaded to load something else. AJAX allows you to get around this hassle.
For your example of form validation, AJAX can be used to validate the information while the person is filling it out. Otherwise, you are required to reload the page each time someone fills out another field in the form.
Another example is from a project that I have worked on. The form required a zip code and would load the appropriate city and county based on the inputted zip. Using strict PHP, I would need the client to download the entire zip table embedded in the HTML/JS (which would add another 100k at least to the download).
Using AJAX, I can get around this. The user can input the zip code, which triggers an AJAX call that downloads the few rows that I need (this will be less than a few hundred bytes, for comparison).
[Edit:] Also, a tip because you said that you were new to AJAX. If your dealing with some form of authentication (logging in, etc.), remember to validate the user on the AJAX pages themselves. Otherwise, tricky users will be able to access sensitive information for your database.
Ajax just adds to the user experience and allows a web application to feel more like a desktop application to users. So they can delete a record and stay on the same page without reloading, you just let the record disappear.
And remember to validate on the server-side, even if you validate on client-side. Your weakest at your client-side as someone can easily just submit the values straight to your script so ALWAYS check on the server-side and do client-side if you would like to add some nice effects etc.
But you will always need to keep in mind that there are people out there who have javascript disable be it a security policy or just because their paranoid. So when you don't have JS enabled you javascript and AJAX requests won't work. So while developing you will need to make sure that if javascript is not their to do the operation that the form is submitted just like a normal HTTP form, this will allow all those paranoid people to also use your application :D.
OR you could always just deny access to those who don't have Javascript enabled but that's not very nice ... So if you want to check if they have javascript enabled checkout - http://www.w3schools.com/TAGS/tag_noscript.asp - for a example.
AJAX is a Javascript client based technology. If js is disable it simply doesn't work.
Php is a server based technology.
In Php you write pages that are dinamically built by the server. Once built they are sent as html to the client.
Using javascript (and Ajax) you can call the server just to request some datas (hint: look at JSON) or just a little html snippet which is plugged in the current page directly by the browser without requesting a full refresh from the server.
With js and AJAX you can achieve a very rich client experience without reloading a full page every time.
I believe nothing will happen if js is disabled. You need js to grab the data.
If you want to use mysql databases, you can use js to access a php script, which can then return any data gathered from a database, rather than doing it in the page.
AJAX is a way for Javascript (client side) to access PHP/ASP/Whatever serverside language you are using. This means, that if you have an PHP script for getting some data from your MySQL database, and want to run that script when the user clicks some random button, AJAX can do that (async)m and you wont have to reload you page to execute the PHP script.
If Javascript is diabled, AJAX won't work.