【问题标题】:Unable To do Post Requests AxiosUnable To do Post Requests Axios
【发布时间】:2022-11-20 23:03:02
【问题描述】:

I had tried everything but unable to solve programs. I used axios to request and for frontend react.js and mongoose and nodejs . I can get request from postman so backend works fine

I am getting in error in browser is..

but while making request unable to do request.

form to submit forms xhr.js:244 POST http://localhost:8000/bills 404 (Not Found)

function BillForm() {
  const [NameOfBill, setNameOfBill] = useState("");
  const [amount, setAmount] = useState(0);
  const [isPaid, setIsPaid] = useState(false);
  const dispatch = useDispatch();

  const handleSubmit = (e) => {
    e.preventDefault();
    var c = { NameOfBill: NameOfBill, Amount: amount, isPaid: isPaid };
    dispatch(createPost(c));
    console.log(c);
  };
  return (
    <form onSubmit={handleSubmit}>
      <h1>Write Bill Details</h1>
      <label>Name of Bill</label>
      <input
        type="text"
        value={NameOfBill}
        onChange={(e) => setNameOfBill(e.target.value)}
        placeholder="NameofBill"
      ></input>
      <label>Amount</label>
      <input
        type="number"
        value={amount}
        onChange={(e) => setAmount(e.target.value)}
        placeholder="Amount"
      ></input>
      <label>is Paid</label>
      <input
        type="radio"
        value={isPaid}
        onChange={() => setIsPaid(!isPaid)}
        placeholder="isPaid"
      ></input>
      <button type="submit">Submit</button>
    </form>

export const createPost = (bill) => async (dispatch) => {
  try {
    const { data } = await api.createBill(bill);
    dispatch({ type: "CREATE", payload: data });
  } catch (error) {
    console.log(error.message);
  }
};

on.js:26 Request failed with status code 404

【问题讨论】:

    标签: javascript axios


    【解决方案1】:

    I just forgot to return value from axios request.

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-08-11
      • 2021-09-19
      • 2022-12-02
      • 2022-12-27
      • 2023-01-06
      • 1970-01-01
      • 2022-12-01
      • 2020-02-09
      相关资源
      最近更新 更多