Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
If you look at this plugin, you'll see I used a totally hacky solution, but I wasn't able to get the AJAX calls to play nicely without a cross-site error in the browser. I have a CURL function that works, but I also failed to figure out how to use it to get JSON for the javascript. https://github.com/mmatthews1981/...
-
dfox428279yAwesome! Like you said, can you just curl/fetch from the API on the backend? I think that should definitely work.
-
dfox428279y@meredithlynn for simplicity, if you make it a backend call, you can just do file_get_contents on the endpoint and that should get you back the result (then you just need to JSON decode it).
-
@dfox CURLing works well, but like I said, I'm unsure how to CURL in such a way that the data is available for the javascript to display. I'd just do it all in PHP, but WP dashboard widgets seem to hate the idea, and it's nicer to use with javascript anyway.
-
dfox428279y@meredithlynn I see what you're saying! I don't think there's any way to hit that endpoint with JS because it will always be cross origin. I can probably put a policy in to allow it but it would have to be a different endpoint.
Looking here, it seems it seems decently straight forward to add ajax functionality to a WordPress plugin: https://sitepoint.com/adding-ajax-t... -
Coderman1249yCORS Is a PITA but helps secure your browser.....unless the hacker can proxy the calls to make them server side and return the response.
Related Rants
Any javascript nerds what to come play with me in a devrant-related project? I need help with cross-origin JSON.
undefined
wordpress
jquery
javascript
github