10 examples of 'ajax call on button click' in JavaScript

Every line of 'ajax call on button click' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
23function AjaxCallbackButton(options) {
24 this._create(options);
25};
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

63function handle_button_click() {
64 if (timer_active) {
65 cancel_timer();
66 } else {
67 start_timer();
68 }
69
70 update_button();
71}
17function ajaxBindCallback()
18{
19 if (ajaxRequest.readyState == 4)
20 {
21 if (ajaxRequest.status == 200)
22 {
23 if (ajaxCallback)
24 {
25 ajaxCallback(ajaxRequest.responseXML);
26 }
27 else
28 {
29 alert('no callback defined');
30 }
31 }
32 else
33 {
34 alert("There was a problem retrieving the xml data:\n" + ajaxRequest.status + ":\t" + ajaxRequest.statusText + "\n" + ajaxRequest.responseText);
35 }
36 }
37}
21function handleClick(event){
22 $.ajax({
23 url: `hello/${event.target.id}`,
24 type: `GET`,
25 success(resp){
26 handleResponse(resp);
27 }
28 });
29}
65function clickHandler(jsavArr){
66 return function(index){
67 unhighlightAll();
68 var valInput = $('#answer');
69 var answer = valInput.val().replace(/\s+/g, '');
70 valInput.val('');
71 jsavArr.highlight(index);
72 jsavArr.value(index, parseInt(answer));
73 exer.gradeableStep();
74 pseudo.setCurrentLine(++highlightedLine);
75 pseudoO.setCurrentLine(++currentLineOld);
76 valInput.focus();
77 }
78}
235function onButtonClick(btn){
236 Ext.example.msg('Button Click','You clicked the "{0}" button.', btn.text);
237}
88function onButtonClick(buttonId, callback) {
89 getById(buttonId).addEventListener("click", callback);
90}
10function buttonClick(clicked_id){
11
12 if (clicked_id == "1"){
13 $.get( "command.php", {
14 key: key, command: "setDigitalOutput&pin=7&output=1"} );
15 }
16
17 if (clicked_id == "2"){
18 $.get( "command.php", {
19 key: key, command: "setDigitalOutput&pin=7&output=0"} );
20 }
21}
15function doAjax(method, url, callback) {
16 if (window.GM_xmlhttpRequest) {
17 GM_xmlhttpRequest({
18 method: method,
19 url: url,
20 onload: callback,
21 });
22 } else {
23 var xhr = new XMLHttpRequest();
24 xhr.onreadystatechange = function() {
25 if (xhr.readyState !== 4 || xhr.status !== 200) return;
26 callback(xhr);
27 };
28 xhr.open(method, url, true);
29 }
30}
392var command = protocol.mouseButtonClick('left', function callback() {
393 test.done();
394});

Related snippets