问题
how can I get the value of the input field to the urlData Object?
<input id="username">
And the JS is:
$('#username').api({
action: 'check username',
urlData: {username: $(this).val()},
onSuccess: function(response){
console.log(response)
},
onError: function(error){
console.log(error)
}
});`
With normal JQuery
i can get it with an $(this).val();
. But in this case it´s empty. How does it work with Semantic UI ?
回答1:
You can try like this
$( "#username" ).keyup(function() {
var value=$(this).val();
$('#username').api({
action: 'check username',
urlData: {username: value},
onSuccess: function(response){
console.log(response)
},
onError: function(error){
console.log(error)
}
});
});
回答2:
for anyone who can't figure out why the request does not run immediately (typed 'abc' then the request just 'ab'), here's the solution!
(I'm going to using example above) You can just add
on:'now'
explicitly make semanticjs api to do request 'now', as the keyup(or any events) handle the rest.
$( "#username" ).keyup(function() {
var value=$(this).val();
$('#username').api({
action: 'check username',
on:'now',
urlData: {username: value},
onSuccess: function(response){
console.log(response)
},
onError: function(error){
console.log(error)
}
});
});
I decide to answer this pretty old question, might be someone needs it!
来源:https://stackoverflow.com/questions/32456380/semantic-ui-how-to-get-data-of-active-input-element