0

I create application to write tag. It uses jQuery deferred and document.write. But when I use this, it always have page reload and the page referrer is disappear.

I have no idea of this. So if you have any idea to solve this problem, please tell me any small things.

Thank you for your help in advance.

The code is below.

    $(function() {

    var funcA = function(){ 
    var d = $.Deferred();
    var func1 = function(d) {
        $.ajax({
            type: 'GET',
            url: 'http://api.openweathermap.org/data/2.5/find?q=London&mode=json&callback=?',
            dataType: 'json',
            success: d.resolve,
            error: d.reject
        });
        return d.promise();
    };
    return func1(d).then(function(data) {

    }, function() {
    });
    return funcA;
    };
    var funcB = function(d){
        var d = $.Deferred();
        d.then(function(){
        });
        d.resolve();
        return d.promise();
    };
    var funcC = function(d){
        var d = $.Deferred();
        d.then(function(){
            document.write('<a href="http://aaa" src="http://test">')
        });
        d.resolve();
        return d.promise();
    };
    def = $.Deferred();
    def.then(function(){
        return funcA().then(function(){
            return funcB().then(function(){
                return funcC().then(function(){
                });
            });
        });
    });

    def.resolve();
});

*This json url is sample. It happens any API.

hoshipeace
  • 51
  • 6
  • 1
    document.write will ALWAYS do this when invoked after page load. So it's not a good idea to use document.write for more than initial page creation tasks – devnull69 Nov 06 '13 at 09:39
  • Thank you for your answer. I understand it is document.write problem. But do you know why it doesn't happen when two deferred? Is there any way to solve this issue using document.write? – hoshipeace Nov 07 '13 at 09:01

0 Answers0