Server does not receive data from ajax call

后端 未结 2 749
伪装坚强ぢ
伪装坚强ぢ 2021-01-27 13:21

I have a problem. I\'m trying to send content of a textarea with an ajax call, but it doesn\'t seem to be working, and I don\'t know why.

There\'s the method called

2条回答
  •  一向
    一向 (楼主)
    2021-01-27 14:03

    1. You can't have a request body in a GET request, you have to use a POST request for that
    2. The string you are constrcting is not valid JSON since:
      • Property names must be strings
      • You have no idea what the user will enter in the textarea - it might contain characters with special meaning in JSON

    Generate your JSON programatically.

    {
      type: "POST",
      url: "Default.aspx/GetStatus",
      data: JSON.stringify({
        statusText: statusText
      }),
      // etc
    

    Obviously, the server side of the process needs to be set up to accept a POST request with a JSON body (instead of the more standard URL Form Encoded format) as well.

提交回复
热议问题