如何通過點擊鏈接而不是提交按鈕來創建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