javascript - URL Encode a string in jQuery for an AJAX request -
i'm implementing google's instant search in application. i'd fire off http requests user types in text input. problem i'm having when user gets space in between first , last names, space not encoded +
, breaking search. how can either replace space +
, or safely url encode string?
$("#search").keypress(function(){ var query = "{% url accounts.views.instasearch %}?q=" + $('#tags').val(); var options = {}; $("#results").html(ajax_load).load(query); });
try encodeuricomponent.
encodes uniform resource identifier (uri) component replacing each instance of characters one, two, three, or 4 escape sequences representing utf-8 encoding of character (will 4 escape sequences characters composed of 2 "surrogate" characters).
example:
var encoded = encodeuricomponent(str);
Comments
Post a Comment