Reputation: 21657
Is it possible to have a piece of code or a function that does the following.
I would like for a javascript file to send a request to a different domain of mine with a variable. This webpage would check the variable against the database and return to the original javascript file the result of being either TRUE or FALSE
Upvotes: 0
Views: 107
Reputation: 2513
I didn't know of JSONP and used a diffrent approach
$.ajax({
type: "GET",
crossDomain:true,
url: 'http://otherdomain/check.php',
success: function(data) {
// check.php response
}
});
and in check.php
<?php
$allowable_hosts = array('http://originaldomain','http://anotherdomain');
if (in_array($_SERVER['HTTP_ORIGIN'],$allowable_hosts))
header('Access-Control-Allow-Origin: *');
//echo "ok"; - your check code
?>
Upvotes: 0
Reputation: 4368
If you are sending requests between domains, you should have a look at http://api.jquery.com/jQuery.ajax/ with the dataType
set to jsonp
to load the response using a script tag.
More details on JSONP: https://stackoverflow.com/search?q=jsonp
Upvotes: 4