如何通过点击链接而不是提交按钮来创建AJAX请求? 我想一旦链接被点击员额从输入字段中的数据如何通过点击链接不提交AJAX请求提交按钮
3
A
回答
1
使用jQuery
$('#link-selector').on('click', function(event) {
event.preventDefault();
$.post('url', {$('form selector').serialize()}, function(json) {
// proccess results
}, 'json');
});
+0
确定url是什么,表单选择器 – choppermio
+0
url是链接。选择器是form/link id或class,就像在css中一样 – 2012-05-24 09:41:06
9
$('selector').click(function(e){
e.preventDefault();
$.ajax({
url: "<where to post>",
type: "POST",//type of posting the data
data: <what to post>,
success: function (data) {
//what to do in success
},
error: function(xhr, ajaxOptions, thrownError){
//what to do in error
},
timeout : 15000//timeout of the ajax call
});
});
1
您可以将用户jQuery和表单序列化功能
$('#A-id-selector').click(function() {
$.ajax({
type:'POST',
url: 'target.url',
data:$('#Form-id-selector').serialize(),
success: function(response) {
// Any code to execute on a successful return
}
});
});
2
这里是AJAX是如何工作的:
$('#link_id').click(function(event){
event.preventDefault(); // prevent default behavior of link click
// now make an AJAX request to server_side_file.php by passing some data
$.post('server_side_file.php', {parameter : some_value}, function(response){
//now you've got `response` from server, play with it like
alert(response);
});
});
相关问题
- 1. 如何通过JQuery提交表单时点击提交按钮
- 2. 通过AJAX提交按钮
- 3. 通过点击CSS按钮提交/检测提交表单
- 4. 在点击提交按钮时提交
- 5. 单击提交按钮后如何点击链接
- 6. 表单提交,虽然点击按钮不是提交按钮
- 7. 如何提交表单不用其他点击提交按钮
- 8. 通过单击链接提交表单,而无需使用提交按钮
- 9. 通过ajax请求提交jQuery.each结果
- 10. 通过ajax请求提交html表单?
- 11. 通过AJAX请求提交表单
- 12. VBA提交按钮点击
- 13. 当点击提交按钮
- 14. 点击提交按钮
- 15. 点击提交后按钮
- 16. jQuery:ajax,点击提交按钮
- 17. 提交按钮点击
- 18. 如何检查链接(a)提交按钮是否被点击
- 19. 如何自动点击手机链接(提交按钮)
- 20. 通过javascript点击的提交按钮不会在IE6中“提交”
- 21. 通过ajax表单提交防止默认提交按钮
- 22. 如何在点击提交按钮
- 23. 如何记录提交表单提交的链接点击?
- 24. 提交不提交按钮
- 25. 提交按钮不提交
- 26. 提交按钮不提交
- 27. 提交按钮不提交
- 28. 如何通过可点击的图像提交按钮?
- 29. 点击提交按钮后点击f5
- 30. 如何使用ajax链接而不是提交表单按钮?
我通过jquery或php – choppermio
http://docs.jquery.com/Tutorials,向下滚动到标题AJAX。附加提示:您应该阅读JavaScript事件,特别是“onclick” – cypherabe