function change_tag(url){
$('.filter_button_confirm').unbind('click').on('click', function(){
...
console.log(url);
$.ajax({
url: url,
type: 'POST',
data: {
...
},
beforeSend: function(){
...
}
})
.done(function(data){
...
})
});
};
When I call the function with argument change_tag('/some_url/') of course it works.
But, change_tag() also works perfectly.
It brings data from the url that I set in the past.
console.log(url) shows 'undefined' so I don't know how it knows the url.
asked Dec 21, 2016 at 14:44
atom Jung
1271 gold badge1 silver badge9 bronze badges
1 Answer 1
Since you're not passing in a parameter to the function, url is undefined and so the ajax call gets called with url: undefined. This is the same as not providing an url, and makes it post to the url you're currently on.
For more info you can check the jQuery page: http://api.jquery.com/jquery.ajax/
James Monger
10.8k9 gold badges66 silver badges99 bronze badges
answered Dec 21, 2016 at 14:47
Robin Dorbell
1,6391 gold badge15 silver badges26 bronze badges
Sign up to request clarification or add additional context in comments.
2 Comments
James Monger
Calling
change_tag() actually calls change_tag with url as undefined, not null.j08691
But the OP says that the console log shows
undefined for the URL and adds that "It brings data from the url that I set in the past.", not the current URLlang-js
urlis given?urlglobally?