简体   繁体   中英

Cross Domain Ajax Call Jquery

I am trying to call a page with ajax, but from another server. This js code runs from bookmark in any page you want and I need to get some data from my server. How could I do this? or maybe connect directly to the database?

I got this code:

$j.getJSON(serverUrl+"isLogin.php?callback=?",function(data){
 //really no need to do anything here, we're just posting data
 //but this will output success
 alert(data);
});

isLogin:

if ($_SESSION['user'] == ''){
     echo json_encode(array("isLogin" => "false"));

} else {
    echo json_encode(array("isLogin" => "true"));
}

How could I make this? I try allot of solutions but none works. This one said no errors, but the alert never appear

Thanks

AJAX (The XMLHttpRequest object) is limited to the same domain for security reasons.

You have a couple ways to go about this:

You can use JSONP if your API supports it. This is very similar to your current AJAX approach. This is jQuery's documentation - http://api.jquery.com/jQuery.getJSON/

Another option is to create a local proxy. This is a little more in depth, but gives you full control. Here's a good article - http://developer.yahoo.com/javascript/howto-proxy.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM