嗯,它应该可以工作,请确保您使用的是component alias
名称而不是使用它的class name
,
只是为了通知我们not passing data from one component to another
只是一个普通的ajax request
,我们从browser to component
如果我声明class class componentOne { ... etc
我们不会使用这个。
然后当we include
它在页面内时,alias name
您需要使用它alias name
来请求 ajax。
![在此处输入图像描述](https://i.stack.imgur.com/KT7Ms.png)
更新(使用不同页面的 ajax 处理程序)
我们需要使用ajax JavaScript API
它会给我们更多的灵活性
你可以使用这个代码
<!-- current page is `test`
we are requesting ajax request on anohter `testing` page which is having
compoTwo component and having `onAjaxReq` ajax handler -->
<button onClick="requestAnotherPage(this)" type="button" class="btn btn-danger" >
My button
</button>
<script>
function requestAnotherPage(th) {
$(th).request('compoTwo::onAjaxReq', {
url: "{{ 'testing'|page }}", // <- this option
// url: "http://timeloger.test/testing",
flash: 1,
data: { id: 2, name: 'hardik'},
handleFlashMessage: function(message, type) {
$.oc.flashMsg({ text: message, class: type })
},
success: function(data) { console.log('success'); this.success(data); }
});
}
</script>
你需要照顾另一个页面的网址
{{ 'testing'|page }}
将生成http://timeloger.test/testing
您需要page File Name
作为参数传递的该页面的 url {{ 'page-name'|page }}
-> 它将生成正确的 url
现在ajax api
可以向another given page url
它提出请求fetch data
。