如何获取自定义模块配置 GUI 以将信息发送到另一个 Web 服务器?
首先,我必须承认我是 Magento 和 PHP 的新手。我正在为我的自定义模块编写配置。我想允许输入一些信息,然后将该信息发送到我的 Web 服务器上的 servlet,在其中进行处理并返回响应并显示在配置 GUI 的只读字段中。
我从各种网络文章和查看其他模块的代码中获得指导。 PayPal 模块是执行类似操作的模块。但是,它会打开一个新的浏览器窗口,用户可以在其中登录并输入详细信息。我只想发送收集的数据并等待响应。
在我的 system.xml 文件中,我指定了一个 frontend_model。在该 frontend_model 中,_prepareLayout 方法将模板设置为我的模板,并且在该模板中我有一个 HTML 按钮。我向该按钮添加了一个 onClick 事件处理程序,该处理程序对我的网站进行 AJAX 调用。毫不奇怪(因为我假设同源策略),AJAX 调用失败,代码为 0。
我想我应该做的是,当用户单击按钮时,请求(包括他们在其他字段中输入的数据)是发送到 Magento 服务器,然后从那里对我的网站进行 AJAX 调用?或者也许我的方法是完全错误的并且有更合适的方法来实现这一目标?
谢谢。
Firstly, I have to admit I am new to Magento and PHP. I am writing the configuration for my custom module. I would like to allow entry of some information, then send that information to a servlet on my web server where it is processed and a response returned and displayed in the configuration gui in a read-only field.
I am getting my guidance from various web articles and by looking at other modules' code. A module that does something similar is the PayPal module. However, it brings up a new browser window where the user logs in and enters their details. I just want to send the data gathered and wait for the response.
In my system.xml file I specify a frontend_model. In that frontend_model, the _prepareLayout method sets the template to my template, and in that template I have an HTML button. I added an onClick event handler to that button which makes an AJAX call to my web site. Unsurprisingly (because of the same origin policy I assume) the AJAX call fails with a code of 0.
I guess what I should be doing is when the user clicks the button, the request including the data they have entered in the other fields, is sent to the Magento server, and the AJAX call to my web site is made from there? Or perhaps my approach is completely wrong and there is a more appropriate way to achieve this?
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您对同源政策的看法是正确的。这里最好的方法是让按钮触发对基于本地 magento 的控制器的 ajax 调用,该控制器本身使用curl 或其他一些 http 请求库将请求转发到远程 servlet 并处理反馈。
You're right about the same origin policy. The best approach here would be to have the button trigger an ajax call to a local magento based controller, which itself uses curl or some other http request library to forward on a request to your remote servlet and process the feedback.
尝试在这里搜索“JSONP”或谷歌搜索相同的内容。根据您使用的 javascript 库,有预制的组件/插件来实现您想要的功能。
Try searching here "JSONP" or google the same thing. Dependent of javascript library you are using there are pre-made components/plugins to achieve what you are after.