PHP Ajax return source - php

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.

Related

I need to push data to browser of all clients which are currently browsing our web page

We are making a app with php in which we want to push data to client browser same in the way in which facebook notificaiton sent by facebook. i know about commet and also have used ajax in past but ajax is not efficeint while commet programing is out of my mind.
Sample can seen at ESPNCRICINFO.COM live scorecard which is automatically pushed
by server to brwoser and than append to document without refreshing. Same app we
have to made.
Simply i need to build some code that send data to all the browser which have our webpage opened. No restrictions. Just need to send to all. So there is no need to check to whom data will be push.
I really need it urgently.
can you use JavaScript setTimeout(function name, seconds) ?
In JavaScript function you can generate .post request for some PHP script which can load messages, when the message will load, you can show it via you JavaScript. the timer will call this function for all people.

Prevent jquery from receiving .post() response or prevent php from returning response

I am given the task to work on an https site with a jquery script which creates .post() requests to a friend site which isn't running on https of the moment.
Whenever my script hits the part where .post() is. Our site's https gets broken and in the console it says:
The page at https://www.Oursite.com/ displayed insecure content from http://www.FriendSite.com/Statistics.php.
Then I went to ask for the php script they have created to receive our data and the php doesn't even display anything. nor my jquery .post() is scripted to display anything.
Any ideas how I can solve this?
They will get https soon, but for now, it's disturbing to see the lock sign at chrome turn yellow.
How can I prevent a php script from not returning a response?
or fix jquery post to not receive any response?

How to get the content of another page without loading in browser

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.

php check open through iframe

I want to check using php if the current page is called by an iframe and not directly in the browser.
It's a page that gets some $_POST parameters while the sending form's target is an iframe, so the page will display in an iframe.
I want to check that using PHP, How?
Thanks.
You can't. PHP runs serverside. It is for all intents and purposes the same thing as the webserver -- it sees HTTP requests and returns responses. An iframe is a clientside mechanism implemented by the browser that simply allows you to display 2 or more html pages (the response payload).
You can use the SERVER HTTP_REFERER
$_SERVER['HTTP_REFERER'];

jQuery mobile get data from remote server with PHP

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/

Categories