Reputation: 27
My web page has multiple ajax requests and all works OK and all of them sending POST requests. On one form (dynamically created by jQuery) I have a button (jQuery-ui). Just that button, nothing else.
On button I attached a click event handler. In that function I have ONLY alert
. When I click on that button, the function is called and alert is displayed. BUT when I click OK on that alert
, somehow I'm sending a GET request.
My web site is on URL: http://localhost:9000/TestProjekat/main/
After pressing OK on alert I'm getting: http://localhost:9000/TestProjekat/main/?naziv=&pokrajina_drzava=-1
Where this come from? I've searched everything... I have no ideas! Help please...
Upvotes: 0
Views: 40
Reputation: 3046
You button triggers the form that's why. You probably also didn't set the method
attribute that's why it does a GET
.
In your handler, do a return false
or e.preventDefault()
to prevent the default behaviour, your form won't get submitted.
Two ways :
$('#myBtn').click(function (e) {
e.preventDefault(); // to cancel the default behaviour
// do stuff here
});
Or :
$('#myBtn').click(function (e) {
// do stuff here
return false; // to cancel the default behaviour
});
Upvotes: 1