-
Notifications
You must be signed in to change notification settings - Fork 252
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Synchronous XHR request not supported, always yielding a 404 error #1384
Comments
Would you be able to provide an example blueprint to help us better understand your issue? |
@bgrgicak Yes - so I was testing with our plugin using this Blueprint JSON below (plugin name redacted here):
Our plugin calls URL: /wp-admin/post.php?post=5&action=edit Chrome console: |
Ajax requests are enabled by default. You can see it by loading wp-admin in Playground and checking the network tab. I assume that something else related to Playground is causing the issue for you. If you can't share the plugin with us, you could debug it yourself by taking a look at the Playground logs (browser console, or click on View Logs in the upper right menu). |
This is really strange -- the URL is exactly the same between what the plugin is posting to and what the wp-admin page is posting to. The only difference I see is in some of the network headers. There are additional security headers which are sent when the plugin javascript makes the request (via
This is the JS code which makes the call:
Does that help at all? |
I don't think it's the security headers. I tried adding them to a heartbeat request and it kept working. The code you provided doesn't work for me because I don't have the To debug it further you could rewrite the request to use Example:
|
This isn't an endpoint, it's just a part of the JSON data being sent -- so not really important. We just use that to ensure the request is coming from Wordpress. Is there any way to test changes to the plugin code in playground without actually committing new code to SVN? |
Yes, you can use the device storage option inside Playground. |
Or you could:
It would be handy to document different workflow options for plugin preview development. Let's link this issue with #772 for the upcoming doc overhaul |
@bgrgicak I figured out what is causing the problem. It is the If I set this to The jQuery docs (https://api.jquery.com/Jquery.ajax/) only say that if you make a synchronous request via cross-domain, it is not supported -- but the call works fine on "real" WP instances, just not in the Playground. Any ideas? |
Great find, I can confirm that async false triggers a 404. Here is an example that returns a 404, but it returns 200 if async is true.
|
From looking at the ajax documentation this part stands out @adamziel please correct me if I'm wrong. @key88sf I would suggest that you to rewrite the code to be async. I'm not sure if Playground would be able to support sync requests, and in general they are a bad practice because they block the browser while running. |
@bgrgicak Cool we can try to rewrite as an async call. I'm sure there are other plugins out there which make sync requests so if possible to support this, that would be great! |
PHP runs in a worker, the only relevant part that would get blocked part is this event listener relaying messages between the service worker and PHP web worker:
The service worker used to talk directly to the web worker via a wordpress-playground/packages/php-wasm/web-service-worker/src/initialize-service-worker.ts Lines 137 to 139 in 16293ba
If this, or any other communication technique would work consistently these days, we could refactor that part. Relevant article: https://web.dev/articles/two-way-communication-guide |
It looks like any calls by plugins to
admin-ajax.php
result in a 404 Not Found error when running inside a playground instance.Is there any way to enable AJAX requests in the blueprint JSON?
The text was updated successfully, but these errors were encountered: