问题
I am getting values on variable "url" but my textbox not geting that values when variable assigned to Tokeninput..instead when i pass values directly to tokeninput my textbox is working..Finally i need to read my text box when i pass variable as tokeninput.. Thanks in advance
<script type="text/javascript">
$(document).ready(function () {
var url;
$.ajax({
type: "POST",
url: "Tokeninput.aspx/GetData",
contentType: "application/json; charset=utf-8",
data: JSON.stringify({ Locale: 'en-US' }),
datatype: 'json',
async: false,
success: function (data) {
xmlDoc = $.parseXML(data.d);
$xml = $(xmlDoc);
$title = $xml.find("status");
if ($title.attr("code") == "0") {
url = ($title.text());
}
},
error: function (e) {
alert("check once...");
}
});
alert(url);
$("#myTextBox").tokenInput([{"name":"Bhai"},{"name":"Bhargavi"},{"name":"Bhargav"},{"name":"Akka"},{"name":"Amma"},{"name":"Anil"},{"name":"Amar"}], {
//$("#myTextBox").tokenInput(url, {
theme: "facebook",
preventDuplicates: true
});
});
回答1:
I believe you need to pass a JSON object as the parameter, not a JSON string.
Try this:
$("#myTextBox").tokenInput(JSON.Parse(url), {
theme: "facebook",
preventDuplicates: true
});
来源:https://stackoverflow.com/questions/25664448/token-input-not-working