Cross domain jQuery $.ajax request fails for PUT (Method PUT is not allowed by Access-Control-Allow-Methods.) -


i doing cross domain requests via jquery's $.ajax access restful php api.
in order have set following headers in php:

header("http/1.1 $code $status"); header('content-type: application/json'); header('access-control-allow-origin: *'); header('access-control-allow-methods: get, post, put'); 

using types get , post works without problems. when put ajax call firefox fails , shows options api.php in network tab of firebug.
in chrome same thing happens first (option request fails message method put not allowed access-control-allow-methods.) chrome follows actual put request works then.

what reason behaviour?

apparently browser first sends options request find out if put (or delete) requests allowed.
since had not allowed options method in access-control-allow-methods failed , did put request after in firefox.
adding options access-control-allow-methods solved problem:

header('access-control-allow-methods: get, post, put, options'); 

Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -