简体   繁体   English

Javascript / Flex通讯用例[需要建议]

[英]Javascript / Flex communication use case [need advice]

I have a web page with a flex component, the flex component is responsible for creating an image from user inputs. 我有一个带有flex组件的网页,该flex组件负责根据用户输入创建图像。

Once an image is ready the user enter some more information in the HTML form and click on the send form button. 准备好图像后,用户可以在HTML表单中输入更多信息,然后单击“发送表单”按钮。

When this button is clicked, javascript calls a function on the flex components which returns the image data as a base64 encoded string. 单击此按钮后,javascript会在flex组件上调用一个函数,该函数以base64编码的字符串形式返回图像数据。

Then with Jquery i do an ajax POST to a django view. 然后用jQuery我做一个ajax POST到Django视图。 The image data is encoded as a string in the "data" option of the ajax POST. 在ajax POST的“数据”选项中,图像数据被编码为字符串。

Once the django view answers back i either redirect with a Javascript call or higlight any possible mistakes. django视图回复后,我可以使用Javascript调用重定向,也可以高亮显示任何可能的错误。

Is that the best way for what i want to achieve ? 那是我想要实现的最好方法吗? (sending form data + image to server at once) (将表单数据和图像立即发送到服务器)

  • Some form have multi encode part when dealing with files should i try to use it ? 某些格式在处理文件时具有多编码部分,我应该尝试使用它吗? with ajax ? 用ajax? how ? 怎么样 ?

Thanks, 谢谢,

Greg 格雷格

As an alternative, you could have Flex submit the base64 image data directly to the server and handle the result. 或者,您可以让Flex直接将base64图像数据提交给服务器并处理结果。 You can do this easily with the URLRequest class. 您可以使用URLRequest类轻松完成此操作。 You may want to test this out to see if it affects the client's performance; 您可能需要对此进行测试,以查看它是否影响了客户的表现。 my guess is that pushing that much data through ExternalInterface to Javascript could cause the browser to hang for a bit. 我的猜测是,通过ExternalInterface将大量数据推送到Javascript可能会导致浏览器挂起一会儿。

Ultimately though it sounds like this Flex app is just a small component in your overall page, so it might make sense to keep the responsibilities of the Flex component as small as possible and do it through AJAX like you presumably handle the rest of your requests in the application. 最终,虽然听起来好像这个Flex应用程序只是整个页面中的一个很小的组件,所以将Flex组件的职责保持尽可能小并通过AJAX来完成,就像您大概会处理其余请求一样,应用程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM