在 UIWebView 中提交表单
我在 UIWebView 中有一个表单与 Web 服务交互,当我提交表单时,数据会发送到 Web 服务,并将结果返回到另一个 UIWebView。这两个 UIWebView 位于导航控制器下,因此当用户提交表单时,它会滑动到另一个视图以显示结果。谁能指出我如何才能实现这一目标?表单元素中的“action”属性应该填写什么?如何将用户输入返回到应用程序以便我可以使用 Web 服务?我是这个领域的新手,任何帮助将不胜感激。谢谢!
更新:
有没有办法将网页视图中的表单数据保存回我的程序?我认为当我单击“提交”按钮时,最好将表单数据保存回程序(即将参数存储到 nsstring 中),然后开始查询 Web 服务。
I have a form in the UIWebView to interact with a web service, when I submit the form, the data gets sent to a web service and it will return the result to another UIWebView. The two UIWebViews are under a navigation controller, so when the use submits the form, it slides to another view to display the result. Can anyone point me out how I can achieve this? What do I fill in the "action" attribute in the form element? How can I get the user input back to the application so I can use the web service? I am new to this field, any help will be appreciated. Thanks!
Update:
Is there a way to save form data from web view back to my program? I think it's better to save form data back to the program (i.e. store params into nsstring) when I click submit button, and then start querying web service.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用该
函数从目标 c 触发 javascript 方法并从该方法获取返回值。
例如
,在 javascript 中
,我怀疑在这里您可能想要反之亦然(从 javascript 调用 obj-c 方法)。这不能直接完成,这是解决方法。
设置一个UIWebViewDelegate,并实现方法webView:shouldStartLoadWithRequest:navigationType:。在您的 JavaScript 代码中,导航到某个虚假 URL,该 URL 对您要传递给应用程序的信息进行编码,例如:
window.location = "someLink://yourApp/form_Subscribed:param1:param2:param3";
在您的委托方法中,查找这些假 URL,提取您需要的信息,采取任何适当的操作,然后返回 NO 以取消导航。
You can use the
function for firing a javascript method from objective c and get a return value from that method.
For example
and in javascript
And I doubt that here you may wanna do vice-versa (Call obj-c method from javascript). This cannot be done directly here is the work around.
Set a UIWebViewDelegate, and implement the method webView:shouldStartLoadWithRequest:navigationType:. In your JavaScript code, navigate to some fake URL that encodes the information you want to pass to your app, like, say:
window.location = "someLink://yourApp/form_Submitted:param1:param2:param3";
In your delegate method, look for these fake URLs, extract the information you need, take whatever action is appropriate, and return NO to cancel the navigation.
如果我正确理解您的问题,我认为以下步骤将帮助您提供解决方案。
[selfpresentModalViewController:webView2Objectanimated:YES];
If I understood your problem correctly, I think following steps will help you to provide the solution.
[self presentModalViewController:webView2Object animated:YES];