Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

content type JQAutocomplete #1232

Closed
adriaon opened this issue Nov 27, 2020 · 4 comments
Closed

content type JQAutocomplete #1232

adriaon opened this issue Nov 27, 2020 · 4 comments

Comments

@adriaon
Copy link

adriaon commented Nov 27, 2020

JQAutocomplete gives json responses. However, the response content type is set to text/plain. Shouldn't that be application/json? This fix works for me:

JQAutocomplete>>#sourceCallback: aOneArgumentBlock
	"A one argument block that will be evaluated with the term the user currently typed. The block is expected to answer a collection of objects."
	
	| term |
	"assignments to temps don't work in GS 2.4
	http://code.google.com/p/glassdb/issues/detail?id=152"
	term := WAValueHolder new.
	self source: ((self jQuery getJson
		json: [ :stream | stream value: (aOneArgumentBlock value: term contents) ];
		callback: [ :value | term contents: value ] value: (JSStream on: 'request.term');
		onSuccess: 'response(arguments[0])'; 
		dataType: 'jsonp') asFunction: #('request' 'response'))

A separate issue, but anyway, for me the char set needs to be set in JQAjax>>#json:

JQAjax>>#json: aRenderable
	"Defines a json rendering callback."

	self dataType: 'json'.
	self respond: [:response |
		response
			doNotCache;
			contentType: (WAMimeType applicationJson charset: self requestContext handler charSet);
			nextPutAll: (WAJsonCanvas builder render: aRenderable)]
@jbrichau
Copy link
Member

jbrichau commented Feb 7, 2021

I believe this used to have issues in some browsers, but that problem should be ancient and I don't see any problems with the change. In fact, you are right that the mimetype should be application/json. Added it! Thx!

@jbrichau
Copy link
Member

It seems the method search:labels: was not adapted accordingly?

@jbrichau jbrichau reopened this May 17, 2023
@adriaon
Copy link
Author

adriaon commented May 17, 2023

Yes, it seems #search:labels:callback: was overlooked....

jbrichau added a commit that referenced this issue Jun 4, 2023
…back in jQueryUI autocompleter should be application/json and not text/plain. Reworked the callback implementation to no longer create intermediate objects for serialization to json but use the json canvas directly.
jbrichau added a commit that referenced this issue Jun 4, 2023
JQAutocomplete (follow-up to issue #1232): content-type for json call…
@jbrichau
Copy link
Member

jbrichau commented Jun 4, 2023

Finalized the fix in #1364

@jbrichau jbrichau closed this as completed Jun 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants