WordPress.org

Make WordPress Core

Opened 5 weeks ago

Closed 5 weeks ago

#40798 closed defect (bug) (invalid)

Backbone.js throws exception with custom endpoint

Reported by: lucrus Owned by:
Milestone: Priority: normal
Severity: normal Version: 4.7.4
Component: REST API Keywords:
Focuses: javascript, rest-api Cc:

Description

You can find a sample plugin attached, that shows the issue. The plugin is supposed to show an alert dialog, but the JS code throws an exception instead.

Please note that I've already tried different combinations of specifying the "wp-api" dependency, and the exception changes as I switch it to a different method (wp_register_script, wp_enqueue_script or both), but still none of them work.

More details here:

https://wordpress.stackexchange.com/questions/266890/rest-api-backbone-and-custom-endpoint

Attachments (1)

rest-api-sample.zip (1.3 KB) - added by lucrus 5 weeks ago.
Sample plugin that shows the issue

Download all attachments as: .zip

Change History (2)

@lucrus
5 weeks ago

Sample plugin that shows the issue

#1 @adamsilverstein
5 weeks ago

  • Milestone Awaiting Review deleted
  • Resolution set to invalid
  • Status changed from new to closed

@lucrus i looked at your code briefly and it looks like you aren't setting up the wp-api client correctly.

Please see the original documentation here: https://developer.wordpress.org/rest-api/using-the-rest-api/backbone-javascript-client/

Also, see this ticket which discusses connecting to multiple namespaces - if your endpoint isn't in the wp/v2 namespace, you need to call wp.api.init with the new namespace. #39683

make sure you clear sessionStorage in your browser when making init changes as the client caches the parsed endpoints.

Closing this ticket because I don't think there is a bug, happy to help you get your code working - ping me in the #core-rest-api slack channel or leave a follow up on your existing stackexchange post.

Note: See TracTickets for help on using tickets.