0

この AJAX 投稿の何が問題なのかを理解するのに苦労しています。データはサーバーに送信され、データベースによって記録されますが、リダイレクトが成功する代わりに、不可解なエラー メッセージが表示されます。正常にリダイレクトされない理由を解決するには、このエラー メッセージから何を取り除く必要がありますか?

編集: POST は、開発者ツールの [ネットワーク] タブで "保留中" として表示されることにも注意してください。

コード:

$('#submit').click(function(e) {

    data = {
      vimeoVideoId : '22077152'
    };

    console.dir(data);

    var url = '/videos/new-entry';

    $.ajax({
      type: 'POST',
      url: url,
      data: data,
      dataType: 'json',
      success: function(response) {
        console.log('response.status == "OK"');
        if (response.status == "OK") {
          window.location.href = '/videos/' + '22077152';
        }
      },
      error : function(error) {
        console.dir(error);
      }
    });
  e.preventDefault();
  return false;
});

エラーメッセージ:

Object {readyState: 4, getResponseHeader: function, getAllResponseHeaders: function, setRequestHeader: function, overrideMimeType: function…}
abort: function (e){var t=e||T;return l&&l.abort(t),k(0,t),this}
always: function (){return i.done(arguments).fail(arguments),this}
complete: function (){if(u){var t=u.length;(function i(t){b.each(t,function(t,n){var r=b.type(n);"function"===r?e.unique&&p.has(n)||u.push(n):n&&n.length&&"string"!==r&&i(n)})})(arguments),n?o=u.length:r&&(s=t,c(r))}return this}
done: function (){if(u){var t=u.length;(function i(t){b.each(t,function(t,n){var r=b.type(n);"function"===r?e.unique&&p.has(n)||u.push(n):n&&n.length&&"string"!==r&&i(n)})})(arguments),n?o=u.length:r&&(s=t,c(r))}return this}
error: function (){if(u){var t=u.length;(function i(t){b.each(t,function(t,n){var r=b.type(n);"function"===r?e.unique&&p.has(n)||u.push(n):n&&n.length&&"string"!==r&&i(n)})})(arguments),n?o=u.length:r&&(s=t,c(r))}return this}
fail: function (){if(u){var t=u.length;(function i(t){b.each(t,function(t,n){var r=b.type(n);"function"===r?e.unique&&p.has(n)||u.push(n):n&&n.length&&"string"!==r&&i(n)})})(arguments),n?o=u.length:r&&(s=t,c(r))}return this}
getAllResponseHeaders: function (){return 2===x?a:null}
getResponseHeader: function (e){var t;if(2===x){if(!c){c={};while(t=Tn.exec(a))c[t[1].toLowerCase()]=t[2]}t=c[e.toLowerCase()]}return null==t?null:t}
overrideMimeType: function (e){return x||(p.mimeType=e),this}
pipe: function (){var e=arguments;return b.Deferred(function(n){b.each(t,function(t,o){var a=o[0],s=b.isFunction(e[t])&&e[t];i[o[1]](function(){var e=s&&s.apply(this,arguments);e&&b.isFunction(e.promise)?e.promise().done(n.resolve).fail(n.reject).progress(n.notify):n[a+"With"](this===r?n.promise():this,s?[e]:arguments)})}),e=null}).promise()}
progress: function (){if(u){var t=u.length;(function i(t){b.each(t,function(t,n){var r=b.type(n);"function"===r?e.unique&&p.has(n)||u.push(n):n&&n.length&&"string"!==r&&i(n)})})(arguments),n?o=u.length:r&&(s=t,c(r))}return this}
promise: function (e){return null!=e?b.extend(e,r):r}
readyState: 4
responseText: "<!DOCTYPE html><html><head><link rel="stylesheet" href="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.1/css/bootstrap-combined.min.css"><link rel="stylesheet" href="/stylesheets/flat-ui.css"><link rel="stylesheet" href="//netdna.bootstrapcdn.com/font-awesome/3.0.2/css/font-awesome.css"><link rel="stylesheet" href="/stylesheets/unislider/dpUniSlider.css"><link rel="stylesheet" href="/stylesheets/styles.css"><link rel="stylesheet" href="/stylesheets/D3.css"><script type="text/javascript" src="http://d3js.org/d3.v3.min.js"></script></head><body><div class="topbar navigation"><div class="fill"><div class="navbar navbar-inverse"><div class="navbar-inner"><div class="container"><ul class="nav"><li><a href="/videos/">Notestream</a></li></ul></div></div></div></div></div><div class="container-fluid"><section class="row-fluid"><div class="span6"><h2 id="video-title"></h2><p id="video-id" class="video-info">5158f3c7fd03dda7f6000002</p><p id="vimeoVideoId" class="video-info">22077152</p><a href="/videos/22077152/destroy">Delete</a></div><div class="span6"><br><div class="btn-group"><button id="your-notes" class="btn">Your Notes</button><button id="all-notes" class="btn">All Notes</button></div></div></section><br><section class="row-fluid"><div id="add-video" class="span6"><iframe id="player" src="http://player.vimeo.com/video/22077152?api=1&amp;player_id=player" width="540" height="304" frameborder="0" webkitallowfullscreen="webkitallowfullscreen" allowfullscreen="allowfullscreen"></iframe></div><div class="span4 note-edit-view"><h4>Your Recent Notes</h4><div id="notes-append"></div></div><div class="span6 unislider-view"><div id="chartSet"><script type="text/javascript" async src="/js/D3/chart.js"></script></div></div></section><br><section class="row-fluid notes-edit-view"><div class="span5 note-edit-view"><form id="noteForm" method="POST" action="/videos/5158f3c7fd03dda7f6000002/note"><fieldset><textarea id="noteText" name="noteText" rows="6" cols="50" placeholder="Add a note" autofocus class="input-xlarge"></textarea><input id="timecode" type="hidden" name="timecode" value="timecode"><input type="hidden" name="videoId" value="5158f3c7fd03dda7f6000002"><input type="hidden" name="author" value="ee"><br><button id="noteButton" type="button" class="btn btn-large">Enter</button></fieldset></form></div></section><section class="row-fluid note-edit-view"><br><a href="/videos/22077152/csv">Download notes</a><br><br></section></div><div class="container-fluid unislider-view"><h4>All Notes</h4><div class="unslider-bkgr">&nbsp;<ul id="unislider"></ul></div></div><script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script><script type="text/javascript" src="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.1/js/bootstrap.min.js"></script><script type="text/javascript" src="/js/unislider/jquery.dpUniSlider.min.js"></script><script type="text/javascript" src="http://a.vimeocdn.com/js/froogaloop2.min.js?8a15a-1360785454"></script><script type="text/javascript" src="/js/notestreamjs/notestream-show.js"></script><script type="text/javascript" src="//use.typekit.net/hbs1mpa.js"></script><script type="text/javascript">try{Typekit.load();}catch(e){}↵&lt;/script></body></html>"
setRequestHeader: function (e,t){var n=e.toLowerCase();return x||(e=v[n]=v[n]||e,y[e]=t),this}
state: function (){return n}
status: 200
statusCode: function (e){var t;if(e)if(2>x)for(t in e)m[t]=[m[t],e[t]];else N.always(e[N.status]);return this}
statusText: "OK"
success: function (){if(u){var t=u.length;(function i(t){b.each(t,function(t,n){var r=b.type(n);"function"===r?e.unique&&p.has(n)||u.push(n):n&&n.length&&"string"!==r&&i(n)})})(arguments),n?o=u.length:r&&(s=t,c(r))}return this}
arguments: null
caller: null
length: 0
name: ""
prototype: Object
__proto__: function Empty() {}
<function scope>
then: function (){var e=arguments;return b.Deferred(function(n){b.each(t,function(t,o){var a=o[0],s=b.isFunction(e[t])&&e[t];i[o[1]](function(){var e=s&&s.apply(this,arguments);e&&b.isFunction(e.promise)?e.promise().done(n.resolve).fail(n.reject).progress(n.notify):n[a+"With"](this===r?n.promise():this,s?[e]:arguments)})}),e=null}).promise()}
__proto__: Object
4

4 に答える 4

0

次を使用して簡単な方法を使用できます。

$.post('http://your.ajax.url/', 'data=1&data2', function(response){
      console.log(response);
}, 'json');
于 2013-04-01T03:57:33.173 に答える
0

変化する:

success: function(response) {
        console.log('response.status == "OK"');
        if (response.status == "OK") {
          window.location.href = '/videos/' + '22077152';
        }
      }

....
success: function(response,  textStatus, xhr) {
    if (xhr.statusText == "success") {
      window.location.href = '/videos/' + '22077152';
    }
}

参照: jQuery.ajax()

于 2013-04-01T03:33:26.087 に答える