Opened 10 years ago
Last modified 5 years ago
#31577 new defect (bug)
wp.ajax.send JS function should send ajax request with dataType json
Reported by: | TikiTDO | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 3.6 |
Component: | General | Keywords: | has-patch |
Focuses: | javascript | Cc: |
Description
Occasionally when using the wp.ajax.send JS function defined in wp-includes/js/wp-util.js:70 the system fails to auto-detect that the response is JSON, even when it is a valid JSON string.
Given that the remainder of the code fails if the response is not a valid object it should be safe to add dataType: 'json' to the default options hash defined on line 78 of that file.
Attachments (1)
Change History (5)
#3
in reply to:
↑ 2
@
10 years ago
Replying to nacin:
I believe what needs to happen is
Content-type: application/json
needs to be returned, correct? If you are using the corresponding PHP API (wp_send_json_success()/_error()
), then you should always have this content type set.
Logically, yes. However, this was affecting a client when they were trying to add an image to a post, even after I had disabled all plugins. Perhaps there might be a deeper root cause, but I found that the attached fix was sufficient for this scenario.
Given that the function in question only deals with JSON responses I figured it would be a good idea to get this in place, that way even if something goes wrong higher up the chain there is still a chance to recover from it. Otherwise I would like to spare a less experienced developer a painful multi-hour bug hunt.
I believe what needs to happen is
Content-type: application/json
needs to be returned, correct? If you are using the corresponding PHP API (wp_send_json_success()/_error()
), then you should always have this content type set.