2017-07-03 15 views
0

私は現在、ローカルホストで簡単なAJAXページ遷移を実行しようとしています。ここでAJAXページの読み込みで[オブジェクトオブジェクト]

は私のhome.html上のタグ

<a href="/blank.html">go to blank</a> 

がblank.htmlページに私を取るべきです。ここで

は私のAJAXです:

$(function(){ 
    jQuery(function ($) { 
     $(document).on('click', "a", function (event) { 
      event.preventDefault(); 
      $.when($("body").fadeOut(1000).promise(), $.ajax({ 
       url: this.href, 
       type: 'get', 
       dataType: 'html' 
      })).done(function (html) { 
       var newDoc = document.open("text/html", "replace"); 
       newDoc.write(html); 
       newDoc.close(); 
       $("body").fadeIn(1000); 
      }); 
     }); 
    }); 
}); 

javascriptの私のリダイレクトが正常に動作しますが、JavaScriptで、フェードアウトした後、それがページ上[object Object]を返します(とリダイレクトされません)なしで

私が持っています解決策を探し回ったが、見つけられないようだ。

ご協力いただきありがとうございます、ありがとうございます!

EDIT:

にconsole.log(HTML)。戻り値:

enter image description here

+0

'はconsole.log(HTML)'の結果は何ですか? –

+0

編集をご覧ください! @MaheshSinghChouhan –

+0

内部は 'blank.html'ですか?あなたのajaxリクエストは通常​​のHTMLコンテンツを 'dataType:" 'html "としていますが、どういうわけかレスポンスがオブジェクトを投げています。それは問題です –

答えて

1

はこれを試してみてください:

$(function(){ 
    jQuery(function ($) { 
     $(document).on('click', "a", function (event) { 
      event.preventDefault(); 
      $("body").fadeOut(1000); 
      $.ajax({ 
       url: this.href, 
       type: 'get', 
       dataType: 'html', 
       success: function(html){ 
       var newDoc = document.open("text/html", "replace"); 
        newDoc.write(html); 
        newDoc.close(); 
        $("body").fadeIn(1000); 
       } 
      }) 

     }); 
    }); 
}); 
関連する問題