Created
May 18, 2011 04:42
-
-
Save buddylindsey/978005 to your computer and use it in GitHub Desktop.
Basic JQuery Ajax
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$("#EnglishName").blur(function () { | |
$.ajax({ | |
url: "/Search/AjaxAddSearch", | |
dataType: "json", | |
data: { | |
showTitle: $("#EnglishName").val() | |
}, | |
success: function (data) { | |
$(".possibleShows").css("visibility", "visible") | |
.html("<pre>"+ data +"</pre>") | |
} | |
}) | |
}); | |
$(document).ready(function() { | |
function lastWord(data){ | |
if(data.indexOf(",") > 0){ | |
var words = data.split(","); | |
return jQuery.trim(words.pop()); | |
} else { | |
return data; | |
} | |
} | |
function split(val){ | |
return val.split(/,\s*/); | |
} | |
$("#show_genres_string").autocomplete({ | |
source: function(request, response){ | |
$.ajax({ | |
url: "/genres/all.json", | |
dataType: "json", | |
data: { | |
genre: lastWord(request.term) | |
}, | |
success: function(data) { | |
response(data) | |
} | |
}) | |
}, | |
minLength: 1, | |
focus: function() {return false;}, | |
select: function(event, ui){ | |
var terms = split(this.value); | |
terms.pop(); | |
terms.push(ui.item.value); | |
terms.push(""); | |
this.value = terms.join(", "); | |
return false; | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment