Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/238.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 10月CMS-AJAX表单从一个组件提交到另一个组件_Php_Laravel_Octobercms_Octobercms Plugins_Octobercms Widgets - Fatal编程技术网

Php 10月CMS-AJAX表单从一个组件提交到另一个组件

Php 10月CMS-AJAX表单从一个组件提交到另一个组件,php,laravel,octobercms,octobercms-plugins,octobercms-widgets,Php,Laravel,Octobercms,Octobercms Plugins,Octobercms Widgets,我在十月份做一个网站 我创建了1个组件,比如组件1和组件2 现在,我想通过表单[通过AJAX数据属性APi]将数据从组件_1发布到组件_2 因此,在我的组件_1中,我有一个表单: <form method="POST" data-request="Component_2::onSubmit" data-request-flash> 然后我在组件_1::onSubmit中有一个相同的函数&当我将此表单提交给组件_1::onSubmit时,我没有收到任何错误 那么,您能建议我一种通过A

我在十月份做一个网站

我创建了1个组件,比如组件1和组件2

现在,我想通过表单[通过AJAX数据属性APi]将数据从组件_1发布到组件_2

因此,在我的组件_1中,我有一个表单:

<form method="POST" data-request="Component_2::onSubmit" data-request-flash>
然后我在组件_1::onSubmit中有一个相同的函数&当我将此表单提交给组件_1::onSubmit时,我没有收到任何错误

那么,您能建议我一种通过AJAX将表单从组件1提交到组件2的方法吗


谢谢

Hmm它应该可以工作,请确保您使用的是
组件别名
名称,而不是其
类名

我们不是在将数据从一个组件传递到另一个组件,这只是一个常规的
ajax请求
,我们将数据从
浏览器发送到组件

如果我声明
class-class-componentOne{…etc
我们将不使用这个

然后,当
我们在页面中包含它时,将出现
别名
,您需要使用该
别名
来请求ajax

更新(使用不同页面的ajax处理程序) 我们需要使用
ajaxjavascript-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>

我的纽扣
功能请求另一页(th){
$(th).request('compotoo::onAjaxReq'{

url:{{‘测试’|第}},//您好,Hardik,感谢您的关注,我使用的是相同的别名,但仍然没有成功,在我的情况下,主页上有组件1,另一个页面上有组件2……基本上,主页上有一个搜索组件,我正在尝试将数据发布到另一个页面上定义的组件,因为我需要第二个组件中的搜索参数,这是定义的在另一个页面上。hmmm,似乎
ajax框架
正在使用
url:window.location.href,
,所以它总是试图
在同一个url上激发ajax
,所以它将
选择相同的页面,而不是其他页面
所以,从当前页面调用不同页面的ajax hander似乎是
不可能的
-我仍然会尝试找到一些工作并发布
<!-- 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>