Ajax with Python - I want to call function that is in default

Asked

Viewed 561 times

1

I want to do a validation in Mysql Database through Ajax. I created a function called validaCNPJ() that is in the controller called Default.

But I don’t know how to put this function in the parameters of Ajax. Someone can give me the path of the stones?

This is my Script that is on the HTML page:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script>
<script>
$(document).ready(function(){
    $("idCnpj").typehead(function(){
         $.ajax({url: "???????? ", success: function(result){
            $("#div1").html(result);
        }});
    });
});
</script>

1 answer

0

It’s not clear which web framework you use but come on:

According to the jQuery API documentation, you can set the attribute method with the POST that will make a POST in any view prepared to receive this data and treat it.

$.ajax({
  method: "POST",
  url: "some.php",
  data: { name: "John", location: "Boston" }
})
  .done(function( msg ) {
    alert( "Data Saved: " + msg );
  });

Beyond the method, we have the url which is where the POST should be done and the attribute data containing the details of your form.

The function done is the callback of AJAX in case of success.

In case it is not clear, I suggest studying this link from W3schools.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.