我在Reflux商店中有以下AJAX呼叫:
$.ajax({
url: 'submit.php',
context: this,
method: 'POST',
dataType: 'json',
success: function(data){...},
error: function(jqXHR, textStatus, error){...}
});
这是我的路线:
let browserHistory = createBrowserHistory();
ReactDOM.render((
<Router history={browserHistory}>
<Route path="/" component={App}>
<IndexRoute component={About} />
<Route path="about" component={About} />
<Route path="leaderboards" component={LeaderboardPage} />
<Route path="profile" component={Profile} />
<Route path="validate/:projectName" component={Validate} />
</Route>
</Router>
), document.getElementById('app'));
每当Validate
组件要求其商店发出AJAX请求时,都会向发出请求,validate/submit.php
而不是发出请求submit.php
。这是怎么回事?
由于您只提供文件名$.ajax
而不是绝对路径或URL,因此浏览器将其用作相对URL。由于当前页面的URL路径是/validate/foo
(history.pushState
不必担心,它是由;浏览器没有区别),因此它假定您要submit.php
相对于该路径请求/validate/submit.php
。
在浏览器中发出请求时,应始终使用绝对路径或完整URL,例如:
$.ajax({
url: '/submit.php',
// ...
});
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句