开发者

ajax on parked domain

开发者 https://www.devze.com 2023-02-03 22:59 出处:网络
I\'m currently writing this jquery and for some reason (I don\'t know why) it works on the normal domain, but on the parked domain it doesn\'t.

I'm currently writing this jquery and for some reason (I don't know why) it works on the normal domain, but on the parked domain it doesn't.

Normal domain - http://www.thefinishedbox.com Parked domain - http://www.tfbox.com

If you scroll down to the colony news and hit the click me link you'll see it will retrieve data via jquery ajax on the Normal domain, but on the parked domain it wont.

Here is the jQuery code I have so far (its pretty standard):

$(function() {

$.ajaxSetup({
    cache: false
});
var ajax_load =开发者_开发知识库 "Load me plz";

//    load() functions
var loadUrl = "http://thefinishedbox.com/wp-content/themes/tfbox-beta/test.php";

$('.overlay').css({
    opacity: '0'
});
$('.toggle').click(function() {
    $('.overlay').css({
        display: 'block'
    }).animate({
        opacity: '1'
    }, 300);

    $(".overlay .content").html(ajax_load).load(loadUrl);

    return false;
});
$('.close').click(function() {
    $('.overlay').animate({
        opacity: '0'
    }, 300);
    $('.overlay').queue(function() {
        $(this).css({
            display: 'none'
        });
        $(this).dequeue();
    });
    return false;
});

I'm a complete noob when it comes to ajax so any help would be massivly appreciated.


Because you can't do Ajax requests on another domain, unless you have set permissions accordingly. It's called "Cross-Domain Ajax".

If you absolutly need to make it work, you can modify your code a bit:

var loadUrl = "http://"+window.location.hostname+"/wp-content/themes/tfbox-beta/test.php";

Or use a workaround (not recommended) : http://www.usejquery.com/posts/9/the-jquery-cross-domain-ajax-guide


Ajax requests are normally prohibited from loading things from other hostnames for security reasons. If you could simply load things from other sites, you could load people's bank details, etc.

A common way of working around this restriction is to use JSON-P, but that requires support from the other website.


You can write this on your php page to store the domainname in a js variable. That way you can use the same code on either domain.

<script type="text/javascript">var domain = '<?php echo $_SERVER['HTTP_HOST']; ?>';</script>
<script type="text/javascript" src="yourJavascriptFile.js"></script>

then use that variable in your js file, like so:

//    load() functions
var loadUrl = domain + "/wp-content/themes/tfbox-beta/test.php";
0

精彩评论

暂无评论...
验证码 换一张
取 消