React Router导致Reflux存储中的AJAX调用失败

马修·赫伯斯特(Matthew Herbst)

我在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/foohistory.pushState不必担心,它是由;浏览器没有区别),因此它假定您要submit.php相对于该路径请求/validate/submit.php

在浏览器中发出请求时,应始终使用绝对路径或完整URL,例如:

$.ajax({
  url: '/submit.php',
  // ...
});

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

React API调用失败

来自分类Dev

React-Router在ajax调用中对setState()引发不变违规

来自分类Dev

React + Reflux:将变量传递到数据存储

来自分类Dev

使用 Redux 和 React Router 在 React 应用程序中的浏览器中重新加载 url 导致存储状态未定义

来自分类Dev

React Starter Kit中的Ajax调用

来自分类Dev

委托或使ajax调用react中的组件

来自分类Dev

如何使React.js组件侦听Reflux中的商店

来自分类Dev

从AsyncTask调用时,startReactApplication失败-Android中的React Native

来自分类Dev

在 React Hooks useEffects 清理失败中取消 Axios REST 调用

来自分类Dev

React 中的永久状态 - React-Router

来自分类Dev

react-redux react-router存储在props中不可用

来自分类Dev

react-redux react-router存储在props中不可用

来自分类Dev

react-router createElement和渲染失败

来自分类Dev

使用React Router的导航测试失败

来自分类Dev

React教程-为什么将其绑定在Ajax调用中

来自分类Dev

React中的Axios AJAX调用仅返回初始状态

来自分类Dev

React在选择过程中调用Ajax请求

来自分类Dev

React 中的 Axios 请求失败

来自分类Dev

React Router中的多个参数

来自分类Dev

结合使用react-redux和对API的ajax调用-如何存储API URL

来自分类Dev

React 中的双重渲染与 componentDidMount 中的异步调用导致错误

来自分类Dev

React Router在哪里使用AJAX

来自分类Dev

在React render中调用函数

来自分类Dev

在React中调用调度功能

来自分类Dev

React.JS - 在 `onClick` 事件上调用函数会导致 `this` 在函数中未定义

来自分类Dev

在Gatsby / React中进行API / Ajax调用

来自分类Dev

React componentDidMount不触发jQuery AJAX调用

来自分类Dev

React 中的 setState 导致 Uncaught ReferenceError

来自分类Dev

React Native 中的模态导致无限循环

Related 相关文章

  1. 1

    React API调用失败

  2. 2

    React-Router在ajax调用中对setState()引发不变违规

  3. 3

    React + Reflux:将变量传递到数据存储

  4. 4

    使用 Redux 和 React Router 在 React 应用程序中的浏览器中重新加载 url 导致存储状态未定义

  5. 5

    React Starter Kit中的Ajax调用

  6. 6

    委托或使ajax调用react中的组件

  7. 7

    如何使React.js组件侦听Reflux中的商店

  8. 8

    从AsyncTask调用时,startReactApplication失败-Android中的React Native

  9. 9

    在 React Hooks useEffects 清理失败中取消 Axios REST 调用

  10. 10

    React 中的永久状态 - React-Router

  11. 11

    react-redux react-router存储在props中不可用

  12. 12

    react-redux react-router存储在props中不可用

  13. 13

    react-router createElement和渲染失败

  14. 14

    使用React Router的导航测试失败

  15. 15

    React教程-为什么将其绑定在Ajax调用中

  16. 16

    React中的Axios AJAX调用仅返回初始状态

  17. 17

    React在选择过程中调用Ajax请求

  18. 18

    React 中的 Axios 请求失败

  19. 19

    React Router中的多个参数

  20. 20

    结合使用react-redux和对API的ajax调用-如何存储API URL

  21. 21

    React 中的双重渲染与 componentDidMount 中的异步调用导致错误

  22. 22

    React Router在哪里使用AJAX

  23. 23

    在React render中调用函数

  24. 24

    在React中调用调度功能

  25. 25

    React.JS - 在 `onClick` 事件上调用函数会导致 `this` 在函数中未定义

  26. 26

    在Gatsby / React中进行API / Ajax调用

  27. 27

    React componentDidMount不触发jQuery AJAX调用

  28. 28

    React 中的 setState 导致 Uncaught ReferenceError

  29. 29

    React Native 中的模态导致无限循环

热门标签

归档