Thursday, November 26, 2009

[jQuery] PHP jQuery on different port

Hello,

This user.php on port 80
$callback = $_GET["callback"];
$user = $_GET["username"];

if($user == "lazy") {
$response = array("message" => "SUCESS");
} else {
$response = array("message" => "FAIL");
}

echo $callback . "(". json_encode($response) . ");";

This is index.html on port 8080

$.getJSON("user.php?callback=?", { username: "lazy"}, function(json){
alert("JSON Data: " + json.message); // SUCCESS
});

This is working if both files on same port, however, it doesn't when
its not on same port

Any workaround for this to work?

No comments: