I’ve got a problem with the jquery autocomplete function. If I specify a source which doesn’t redirect, my autocomplete works without problems (this was in my test environement). For production, this has to work in our workflow tool.
The page for the jquery source is also written in this workflow tool, and does output the data. Only problem is, when I call this output page with the GET parameters, it redirects me to another page containing the JSON results.
jquery seems to have a bit of a problem with that, since I don’t get any suggestions.
This is the jquery for the input field:
$(function() {
$("#unameLeiter").autocomplete({
source: function(request, response) {
$.ajax({
url: "http://localhost:8082/ivy/pro/designer/ldapCurrent2/137553578A7A2B3F/persons.ivp",
dataType: "jsonp",
data: {
search: request.term
},
success: function(data) {
response($.map(data.persons, function(item) {
return {
label: item.cn,
value: item.imPersonalNumber
}
}));
}
});
},
minLength: 0,
select: function(event, ui) {
$("<div/>").text(ui.item.label + " " + ui.item.value).prependTo("#output");
}
})
})
The HTML looks pretty nasty, but that’s not the important part, since there’s just the input field and the output div. When I watch the network requests, I can see that jquery makes proper calls to the “source” url, but then gets redirected to another URL (the results shown there are what I searched for).
So, how do I handle sources in jquery, which redirect to the actual output?
To summarize
- jquery sends data like this
http://source/persons.ivp?callback=jquery87346&search=John - Workflow tool takes the parameters, processes them and redirects to a new url
http://source/L84FJ8LA4LS/CMSObject.ivc?taskId=84&processId=LKIA47&pid=KS4U6T84LSZ - The new URL contains the results for the parameter
John - jQuery doesn’t handle the result due to an
302 permanently movedredirect.
I have no way of changing the behaviour of this workflow tool. So I’ll have to solve this with jQuery.
Update: I noticed that the JSP file which outputs the JSON data, html-encodes my output, which seems to disturb jquery. Does anybody know how I can print data in JSP without html-encoding it?
How it looks when I view source-code of output-page:
jquery1234({"total":"2", "persons":[{"cn":"John Smith", "imPersonalNumber":"5616"},{"cn":"Peter Jackson", "imPersonalNumber":"7016743"}]})
How it looks normally:
jquery1234({"total":"2", "persons":[{"cn":"John Smith", "imPersonalNumber":"5616"},{"cn":"Peter Jackson", "imPersonalNumber":"7016743"}]})
As it turned out, the problem wasn’t the redirect. It was the fact that the tool escaped the whole data. After I found out how to prevent him from doing so, everything worked fine.