【问题标题】:React-native axios with ColdFusion component带有 ColdFusion 组件的 React-native axios
【发布时间】:2018-12-15 17:03:54
【问题描述】:

我正在尝试使用 axios 从 react native 向我的coldfusion组件发送一个get请求。

我的冷融合组件:

component displayName="react" {

remote any function ajaxLogin(data) returnformat="JSON"{
    data = deserializeJSON(arguments.data);
    return serializeJSON(login(data));
}

private any function login(data){
    loginQuery = new query();
    loginQuery.setDatasource("ds");
    loginQuery.setName("loginQuery");
    loginQuery.addParam(name="UserEmail",       value="#arguments.data.userEmail#",     cfsqltype="cf_sql_varchar");
    loginQuery.addParam(name="UserPW",      value="#arguments.data.userPassword#",      cfsqltype="cf_sql_varchar");
    result = loginQuery.execute(sql="SELECT * FROM Users Where UserEmail = :UserEmail AND UserPW = :UserPW");
    rs = result.getResult();
    if(rs.recordCount == 0){
        return 0;
    } else {
        return rs.UserID;
    }
}

}

我的 react-native 调度操作:

export const loginUser = ({ email, password }) => {
  // login
  return (dispatch) => {
    dispatch({ type: 'TEST' });
    axios.get('https://myserver.com/components/reactNative/react.cfc?method=ajaxLogin', {
      params: {
        userEmail: email,
        userPassword: password
      }
    })
      .then((response) => {
        console.log(response.data);
      })
      .catch((err) => {
        console.log(err);
      });
  };
};

它从 catch 返回一个错误:

Error: Request failed with status code 500

我是 axios 和 react-native 的新手。我使用axios错了吗?

谢谢

【问题讨论】:

标签: react-native coldfusion axios


【解决方案1】:

状态码 500 是服务器端错误,因此您很可能遇到 ColdFusion 错误,请检查您的 ColdFusion 日志。

此外,当您将其称为 GETrequest 时,您只需在浏览器选项卡中打开 URL,然后查看是否有任何错误转储到页面(在开发环境中)

https://myserver.com/components/reactNative/react.cfc?method=ajaxLogin&userEmail=email&userPassword=password

如果这是生产,那么您应该会在错误日志中看到错误(类似于 Linux 上的 /var/www/opt/coldfusion_11/cfusion/logs

【讨论】:

    猜你喜欢
    • 2021-07-12
    • 2019-04-07
    • 2018-11-06
    • 1970-01-01
    • 2018-12-06
    • 2021-06-14
    • 2020-05-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多