$('#groupnamesearch').blur(function () {
str = $('#groupnamesearch').val()
$.get("injectgroup.php", {
name: str
}, function (data) {
//here i guess str.replace data
$('#aspecforgroup').val(data);
});
});
This gives me results like: [“45054″,”55905″,”42306”]
I’d like to strip all []” of them, so I have only numbers and the , character.
How can I manipulate the data that came over the ajax request before it’s getting populated in an input field?
Thanks 🙂
If the result that you are getting back in
datais an actual string – and I assume it must be if the square brackets are getting displayed in your “aspecforgroup” field – then you can remove those characters as follows:Or you can tell jQuery (that is jQuery that you’re using?) to treat the response as JSON in which case it should be automatically parsed into an array by the time it ends up in the
dataparameter and then you can use the array.join()method to turn that into a string:The parameter to
.join()is the string to join the individual elements with. If you leave it out it will be a comma by default, but you might want to use a comma plus a space:.join(", ").