JavaScript Post Method
JavaScript Post Method
我是JavaScript的新手,偶然发现了一些我很难解决的问题。我想将表单中的数据发布到服务器,但单击提交按钮后,它似乎没有发送信息。如有任何帮助,我们将不胜感激!
JAVASCRIPT:
$("#sendFeedbackButton").click(function(){
$.post("Link to the server", $("#feedbackform").serialize())
alert("Thanks for the feedback");
});
HTML:
<form id="feedbackform" name="feedbackform">
<textarea id="name" name="name" cols="10" rows="5"></textarea>
<input type="email" id="email" name="email">
<textarea id="comment" name="comment" cols="30" rows="5"></textarea>
<input type="button" id="sendFeedbackButton" value="Send feedback"/>
</form>
更改
$("sendFeedbackButton")
至
$("#sendFeedbackButton")
$("sendFeedbackButton").click(function(){
你忘了#
$("#sendFeedbackButton").click(function(){
您必须使用#
用于id
,使用.
用于class
示例
$('#id')
$('.class')
$("#sendFeedbackButton").click(function(){
$.post("ajax-or-whatever-.php", $("#feedbackform").serialize(), function(response_from_server){ // this function runs after the infos have been sent and the server responded
alert("Thanks for the feedback" + response_from_server);
});
return false; // don't let the form submit and refresh, instead run code above
});
这里是$.ajax
的演示。it响应错误服务器,因为我没有服务器,但若服务器存在,它应该是可以的。你可以在网络中看到这个调用,它转到这个演示中的错误函数,因为不存在服务器并发出警报。
http://jsfiddle.net/nn007/sAaLU/
试试这个:
$("#sendFeedbackButton").click(function(){
而不是
$("sendFeedbackButton").click(function(){
$("#sendFeedbackButton").click(function(){
$.post("Link to the server", $("#feedbackform").serialize())
alert("Thanks for the feedback");
});
注意sendFeedBackButton 前面的#
相关文章:
- 如何使用WCF服务和javascript表单post上传.doc文件
- Jquery POST未填充数组
- 如何在php文件中获取$.post-ajax传递的值
- 在POST中将html表作为csv提交
- JS表单提交"无法使用Chrome数据保护程序加载此页面.尝试重新加载页面.调试信息:POST CISmtuK
- 如何使用post方法从方法上传文件
- Django: AJAX + CSRF POST gives 403
- 当method=post时,jQueryAjax返回404
- JavaScript Post Method
- Javascript and AJAX post method
- AngularJS在使用method:POST时$resource调用错误的API URL
- Jquery ajax with google app engine post method
- ExpressJS POST Method
- $("#form").attr("method", "post&quo
- return request method = GET but i send request = POST (ajax)
- 都不是:method =>:post and:remote =>true正在我的Rails 3.1应用程序上工作
- Rails 3 link_to method: :post, remote: true prototype
- 将数据发送到php(form-method=post),然后将其发送回javascript
- angularjs http post method
- AJAX POST METHOD