Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
135 views
in Technique[技术] by (71.8m points)

javascript - 如何捕获form.submit的响应(How do I capture response of form.submit)

I have the following code:(我有以下代码:)

<script type="text/javascript"> function SubmitForm() { form1.submit(); } function ShowResponse() { } </script> . . . <div> <a href="#" onclick="SubmitForm();">Click</a> </div> I want to capture the html response of form1.submit ?(我想捕获form1.submit的html响应?) How do I do this?(我该怎么做呢?) Can I register any callback function to form1.submit method?(我可以在form1.submit方法中注册任何回调函数吗?)   ask by nmdr translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You won't be able to do this easily with plain javascript.(使用普通的javascript,您将无法轻松完成此操作。)

When you post a form, the form inputs are sent to the server and your page is refreshed - the data is handled on the server side.(发布表单时,表单输入将发送到服务器并刷新页面 - 数据在服务器端处理。) That is, the submit() function doesn't actually return anything, it just sends the form data to the server.(也就是说, submit()函数实际上不返回任何内容,它只是将表单数据发送到服务器。) If you really wanted to get the response in Javascript (without the page refreshing), then you'll need to use AJAX, and when you start talking about using AJAX, you'll need to use a library.(如果你真的想在Javascript中获得响应(没有页面刷新),那么你需要使用AJAX,当你开始讨论使用AJAX时,你需要使用一个库。) jQuery is by far the most popular, and my personal favourite.(jQuery是迄今为止最受欢迎的,也是我个人的最爱。) There's a great plugin for jQuery called Form which will do exactly what it sounds like you want.(有一个很棒的jQuery插件叫做Form ,它可以完全按你想要的那样做。) Here's how you'd use jQuery and that plugin:(这是你如何使用jQuery和插件:) $('#myForm') .ajaxForm({ url : 'myscript.php', // or whatever dataType : 'json', success : function (response) { alert("The server says: " + response); } }) ;

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...