AJAX value sending error

后端 未结 5 1151
清歌不尽
清歌不尽 2021-01-19 05:13

Hi I have problems with the script below. The problem I think lies on data that need to be sent to php via AJAX.

jQuery

$(\'.send\').live(\"click\",          


        
5条回答
  •  别那么骄傲
    2021-01-19 05:55

    I will put my comment as an answer.

    Apart from using a deprecated jQuery API, what others didn't point out is the following:

    What you are doing in the below line:

    contentType: 'application/json; charset=utf-8',
    

    is that you are promising the server that the HTTP entity will be a JSON-string, which is not the case. It is actually the usual percentile-encoded string. (a=b&c=d&e=f).

    If you remove that line, the browser sends a default value Content-Type as application/x-www-url-form-encoded. That would trigger PHP to parse the HTTP entity as such and give you as the $_REQUEST array properly populated.

提交回复
热议问题