Fingerprint crashes when o.data is a string#98
Fingerprint crashes when o.data is a string#98Esam-Bdeir wants to merge 1 commit intocorejavascript:masterfrom
Conversation
new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.whitespace,
queryTokenizer: Bloodhound.tokenizers.whitespace,
aprefetch: '',
remote: {
url: .....',
prepare: function(query, settings) {
settings.type = 'POST';
settings.contentType = 'application/json; charset=UTF-8';
// Data will go into POST request body, not querystring
settings.data = JSON.stringify({ q: query });
return settings;
}
}
});
In the above scenario, settings.data should go into the request body, not into querystring. The argument name-value pairs should be in JSON format (eg {"objName":"Value"}), not in querystring format (eg objName=Value).
Therefore, we set settings.data = JSON.stringify({ q: query }); - a string value.
However, this doesn't bode well for function fingerprint(o):
$.param(o.data || {}) crashes because it does not expect a single string value.
jlbooker
left a comment
There was a problem hiding this comment.
Looks good to me.
It is a bit interesting that you're using the typeahead with POST requests, since GET requests are more appropriate for fetching typeahead suggestions. However, if this is all that's required to make POST requests work too, then I suppose there's no harm in being flexible on request type.
Can I get another review from @corejavascript/collaborators please?
|
I have special business case using post. But I use both in my application (get,post). Skickat från min Samsung Galaxy-smartphone. -------- Originalmeddelande -------- @jlbooker approved this pull request. Looks good to me. It is a bit interesting that you're using the typeahead with POST requests, since GET requests are more appropriate for fetching typeahead suggestions. However, if this is all that's required to make POST requests work too, then I suppose there's no harm in being flexible on request type. Can I get another review from @corejavascript/collaboratorshttps://github.com/orgs/corejavascript/teams/collaborators please? You are receiving this because you authored the thread. |
| //$.param(o.data || {}) crashes because it does not expect a single string value. | ||
| //if o.data is string no need to call param | ||
|
|
||
| return o.url + o.type + (o.data &&_.isString(o.data) ? o.data : $.param(o.data || {})); |
There was a problem hiding this comment.
Are you missing a space here? (o.data &&_.isString(o.data) seems like it should be (o.data && _.isString(o.data).
new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.whitespace,
queryTokenizer: Bloodhound.tokenizers.whitespace,
aprefetch: '',
remote: {
url: .....',
prepare: function(query, settings) {
settings.type = 'POST';
settings.contentType = 'application/json; charset=UTF-8';
// Data will go into POST request body, not querystring
settings.data = JSON.stringify({ q: query });
return settings;
}
}
});
In the above scenario, settings.data should go into the request body, not into querystring. The argument name-value pairs should be in JSON format (eg {"objName":"Value"}), not in querystring format (eg objName=Value).
Therefore, we set settings.data = JSON.stringify({ q: query }); - a string value.
However, this doesn't bode well for function fingerprint(o):
$.param(o.data || {}) crashes because it does not expect a single string value.