Вы должны использовать Ajax
Пример В Javascript
<!DOCTYPE html>
<html>
<head>
<script>
function loadXMLDoc()
{
var xmlhttp;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","Your URL",true);
xmlhttp.send();
}
</script>
</head>
<body>
<h2>AJAX</h2>
<button type="button" onclick="loadXMLDoc()">Request data</button>
<div id="myDiv"></div>
</body>
</html>
Вы также можете посмотреть в Jquery AjaxJquery Ajax Doc
примера в Jquery Taken from Here
$.ajax({
url: 'getTwitterFollowers.php',
type: 'GET',
data: 'twitterUsername=jquery4u',
success: function(data) {
//called when successful
$('#ajaxphp-results').html(data);
},
error: function(e) {
//called when there is an error
//console.log(e.message);
}
});
-----------------------------------------------------
PHP - GET NUMBER FACEBOOK FANS & TWITTER FOLLOWERS
-----------------------------------------------------
< ?php
//get data passed to script
$username = htmlspecialchars(strip_tags($_GET["twitterUsername"]));
//get twitter followers
$api_page = 'http://twitter.com/users/show/' . $username;
$xml = file_get_contents ($api_page);
$profile = new SimpleXMLElement ($xml);
$count = $profile->followers_count;
$tfans = strval ($count);
//get facebook likes
$fuser = json_decode(file_get_contents('http://graph.facebook.com/140918675956744/'));
//return result
echo "jQuery4u has " . $fuser->likes . " Facebook fans and " . $tfans . " Twitter followers.";
?>
для домена Ajax Cross Вызов вам потребуется JSONP продукта примера jsonp.php
<?php
$callback ='mycallback';
if(isset($_GET['mycallback']))
{
$callback = $_GET['mycallback'];
}
$arr =array();
$arr['name']="Ravishanker";
$arr['age']=32;
$arr['location']="India";
echo $callback.'(' . json_encode($arr) . ')';
?>
Jquery код для JSONP
$.ajax({
url : "http://hayageektest.appspot.com/cross-domain-cors/jsonp.php",
dataType:"jsonp",
jsonp:"mycallback",
success:function(data)
{
alert("Name:"+data.name+"nage:"+data.age+"nlocation:"+data.location);
}
});
Пример из here
'.load JQuery (в) и' .ajax() 'функции используются для загрузки данных из веб-сервера. См. Также http://stackoverflow.com/tags/ajax/info. Однако это будет отправлять запросы только серверу происхождения, если только удаленный сервер не имеет CORS. – Paul