0

I want to know how to send data using Javascript. This is what I tried so far:

$('A').on("click", function(){
    $.ajax({
        type:"POST",
        url: "/cccc",
        data: {user: 'a'},
        success: function(response){
            alert(response);
        },
        error: function(data)
        {
            alert(data.responseText);
        },
});

I've tried above ajax function but nothing happens.


Also i curious that if there is more simple function like

$('A').on("click", function(){
   post('/cccc', make_params(a:'a')
});

Hope someone can answer above 2 questions! Thanks!

Cartucho
  • 3,257
  • 2
  • 30
  • 55
임지웅
  • 121
  • 1
  • 1
  • 8
  • Possible duplicate of [JavaScript post request like a form submit](https://stackoverflow.com/questions/133925/javascript-post-request-like-a-form-submit) –  Dec 06 '18 at 10:59

1 Answers1

0

Of course if you use jQuery library, it will work:

$('some_selector').on('click', function(){
    $.post(
       '/cccc',
       {
           user: 'a'
       },
       function(response){
           alert(response);
       }
    }
});
Ilkin Alibayli
  • 134
  • 2
  • 9