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/
Related
I have a project where i'm calling a php file from jquery ajax.Inside the php file i have a curl call to a rest API to have some data.This data flow cannot be altered i.e from jquery i call the php file then from php file the api will be called.Now i have to prevent displaying the url in the firebug console when the ajax call is triggered.Any idea how can i achieve this? Here is the code i used for calling the php file.
$.getJSON("file.php",function(data) {
console.log("hello"+data);
});
Now i have to prevent displaying the url in the firebug console when the ajax call is triggered.
Sorry, not possible. If the user's web browser is making a request, the user can see it. Even if you manage to somehow hide it from the web browser, they can still see it in any number of other tools. Any request that comes from the user's machine can be inspected by the user.
If you absolutely need to make this happen, then you need to write a custom client and perform encrypted communication between that client and your server.
Now to the real question... why should this be hidden from the user? If the user shouldn't see the data, then why is the request being made client-side in the first place? Just make the request from server-side code and keep the data server-side. If the user should see the data, then what's the problem? If the user only shouldn't see the URL but should see the data, get the data server-side and only show the data to the user.
If you have a public URL which is providing requestors with sensitive information and you don't want anybody to know what that URL is, you have a security problem. As mentioned in a comment above, security through obscurity is no security at all.
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
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've got the following problem, I send some value from jQuery to PHP via AJAX. My PHP script receives those value, and I would like that this script prints values in iframe in my www site. But instead, the script response contains all its source code to AJAX as response to the alert message. Does anybody know how can I stop returning code to AJAX and execute it by returning the values to be used in my iframe?
EDIT:
further details: the problem is that my application has got two iframes from different servers, and I need to send values from one iframe to another. Because of cross domain restrictions, I cant do this via JS directly, so I figured out to send values via AJAX from one iframe to PHP on first server and PHP from first server to PHP on another server which is in iframe on my main page, and then show the data. so I must use AJAX to send it.
You can't. PHP doesn't know about the iframe.
You are, presumably, using XHR to make the request, therefore XHR will receive the response.
If you want to load a document into an iframe, then load a document into the iframe (e.g. by setting its src to the URI for the document), don't play around with Ajax.
I am using PHP to generate a dynamic web form that uses an external (to my site) javascript file to set a hidden form input value. My form submits to my own PHP page before reposting to an external site. The external site requires this hidden value for any submission.
Many of the browser that are using my form do not have javascript enabled, so the tracking fails and I can not submit to the external site. Is there any method of executing the javascript file to get the tracking information from my php code without sending it to the clients browser?
This is a pseudo code mock up of the code that I want to handle the form's post:
if ($doPOST) {
//Check POSTed parameters for tracking id ($tid)
if ($tid == ''){
//Execute external javascript to get tid
}
//Post form data to external site
}
I have looked around and could not find any relevant information, but if you know of a site where this is explained let me know. For clarification, I am not looking for information about to incude a javascript file client side.
Edit:
This is the Javascript executed by the form. I have no power to change this script. The number 48891 is not hardcoded in the script it changes with execution:
onReady=(function(ie){var d=document;return ie?function(c){var n=d.firstChild,f=function(){try{c(n.doScroll('left'))}catch(e){setTimeout(f,10)}};f()}:/webkit|safari|khtml/i.test(navigator.userAgent)?function(c){var f=function(){/loaded|complete/.test(d.readyState)?c():setTimeout(f,10)};f()}:function(c){d.addEventListener("DOMContentLoaded",c,false)}})(/*#cc_on 1#*/);
var test_track=function(data){onReady(function(){document.getElementById('test_track').value = data.TID})}
test_track({"TID" : "488891"});
Yes, you can execute JavaScript server-side. However, it wouldn't make much sense just for a snippet, and you wouldn't be able to access the DOM. See the v8cgi project for a server side JavaScript implementation.
Just rewrite it in PHP.
No. If JavaScript is disabled on the clients browser you cannot get info out of the browser. I suggest you use PHP for tracking
If you are under time pressure (I am not saying this is a good idea), you can parse out the TID value and write it in the hidden form value 'test_track'.
You can get the content of the javascript with:
$js = file_get_contents('http://example.com/source.js');