可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
I want to use Angular JS for October CMS. But how to i POST data to the controllers?
I found this in the October framework.js file
headers: {
'X-OCTOBER-REQUEST-HANDLER': handler,
'X-OCTOBER-REQUEST-PARTIALS': this.extractPartials(options.update)
},
But i have a hard time debugging it.
What is the URL this posts to? And how would i use this.extractPartials(options.update)
回答1:
If you want to post a simple data to the controller and want to update the view file, then you better go with october cms convenient way of handling AJAX through data attributes.
Refer the documents https://octobercms.com/docs/cms/ajax. You can go with java script ajax api only if there is a complex situation like posting a file data and so on..
回答2:
seems you want to fire AJAX using angular.
you just need handler as another part "partial thing" that you can handle by your self as you are firing request.
X-OCTOBER-REQUEST-HANDLER:<<_class_name>>::<<_action>>
<<_action>> -> here you need method which has prefix "on"
onListUpdate something like that.
then October will automatically find that controller and that action and return you json response and you can use that response as you like.
回答3:
I don't know much about JS frameworks however, I think Octobers standard response data is rendered html and scripts/styles to be injected by the framework. Instead you should create your own Routes and return the appropriate response.
E.g:
# Author/Plugin/Plugin.php
public function onBoot() {
Route::get('ajax/endpoint', function() { return Post::all() });
});