$(".button").click(function(e){
//prevent default action
e.preventDefault();
var data={data1:'data1',data2:'data2',action:'ajax_action'};
$.ajax({
url:'http://example/url',
method: 'POST',
data: data,
dataType: 'text',
beforeSend: function(){
//show something from here..for eg show loader gif or somethind else
},
success: function(response){
// do something here while success
},
error: function(){
//do something while error
}
})
})
Simple ajax request when button clicked with jquery
1 Response
Write a comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.