SeasideSt / Seaside

The framework for developing sophisticated web applications in Smalltalk.
MIT License
519 stars 71 forks source link

content type JQAutocomplete #1232

Closed adriaon closed 1 year ago

adriaon commented 4 years ago

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 commented 3 years ago

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 commented 1 year ago

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

adriaon commented 1 year ago

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

jbrichau commented 1 year ago

Finalized the fix in https://github.com/SeasideSt/Seaside/pull/1364