? Error

User tests: Successful: Unsuccessful:

avatar piotrmocko
piotrmocko
18 Sep 2013

Internet Explorer older than 10 does not accept
Content-Type: application/json
and would start to download it.
But this one would work for older IE and all new browsers
Content-Type: text/plain

When you send ajax request by jQuery just set header:

$.ajax({
    url: ...,
    dataType: 'json',
    headers: {
        Accept: 'application/json'
    },
    accept: 'application/json'
}).done(function(data, textStatus, jqXHR) {
    ...
});

and then server would respond with:
Content-Type: application/json

Also we should use

JResponse::toString();

because in ajax method on server side there might be set some other headers by

JResponse::setHeader(...);
avatar piotrmocko piotrmocko - open - 18 Sep 2013
avatar piotrmocko
piotrmocko - comment - 18 Sep 2013

I am also wondering what to do with system messages if any was set due to an error or warning.
I am using something like this in my extensions, but I am not sure if it is a good idea. If whole Joomla CMS libraries do not set any message then it would be not necessary.
For example when sending emails is disabled in global configuration you will get

JFactory::getApplication()->enqueueMessage(JText::_('JLIB_MAIL_FUNCTION_OFFLINE'));

Here is my code if needed

    // Catch all system messages
    $messages = $app->getMessageQueue();
    $logs = array();
    foreach ($messages as $message) {
        $logs[] = $message['type'] .': '. $message['message'];
    }

    if (is_array($result))
        $result['debug'] = count($logs) ? $logs : null;
    elseif (is_object($result))
        $result->debug = count($logs) ? $logs : null;
avatar piotrmocko
piotrmocko - comment - 18 Sep 2013

And one last thing to discuss is if we should allow to load module language file, because you might want to respond with some message or we leave this to decide by developer in his method

$lang = JFactory::getLanguage();
$lang->load('mod_' . $module);
avatar piotrmocko
piotrmocko - comment - 18 Sep 2013

Next thing to discuss is if we should load module parameters like in:
libraries/joomla/document/html/renderer/module.php
and this give next question if we should pass module ID to ajax call.

All of this can be done by developer if he need this, but in most cases ajax call would be related to one module instance with parameters.

avatar brianteeman
brianteeman - comment - 13 Oct 2013

Thanks for your contribution - At this time we are only using github as the place to submit code fixes, the actual reporting of issues and testing fixes is still taking place on Joomlacode.

Please can you:

1) Open an item on the Joomlacode tracker in the appropriate area.

CMS Bug Reports: http://joomlacode.org/gf/project/joomla/tracker/?action=TrackerItemBrowse&tracker_id=8103

CMS Feature Requests: http://joomlacode.org/gf/project/joomla/tracker/?action=TrackerItemBrowse&tracker_id=8549

2) After submitting the item to the Joomlacode tracker, add a link to the Joomlacode tracker item here and make sure that you add a link to this GitHub issue or pull request on the joomlacode tracker item.

avatar betweenbrain
betweenbrain - comment - 6 Dec 2013

As com_ajax now uses JResponseJson, I don't think this would necessary any more. Would you be able to update #2166 to reflect that?

avatar piotrmocko
piotrmocko - comment - 6 Dec 2013

In this thread actual is

  • loading module language,
  • loading module params for given module ID
  • response Content-Type: text/plain for IE < 10
avatar betweenbrain
betweenbrain - comment - 6 Dec 2013

Thanks. Please corret me if I'm wrong, but in your commit piotrmocko@8f4da44, I only see code related to

response Content-Type: text/plain for IE < 10

which I think is superseded by the use of JResponseJson, please see https://github.com/joomla/joomla-cms/blob/master/components/com_ajax/ajax.php#L146.

I'd suggest creating separate PRs for the other two items, as they are also very good ideas.

avatar piotrmocko
piotrmocko - comment - 7 Dec 2013

I will put later those things as separated PR.

JResponseJson does not change Content-type of response. It only generates encoded output. Content-type is being set by JDocument and if you put in URL format=json then response will have Content-type: application/json, but it would not work in IE < 10 without latest updates.

avatar wilsonge
wilsonge - comment - 26 May 2014

JRepsonse is now deprecated in favour of the new JApplication classes that came in 3.2 so can we use them please in the PR?

avatar piotrmocko
piotrmocko - comment - 27 May 2014

I have just open a fresh PR
#3653

avatar piotrmocko piotrmocko - change - 27 May 2014
Status New Closed
Closed_Date 0000-00-00 00:00:00 2014-05-27 08:02:51
avatar piotrmocko piotrmocko - close - 27 May 2014
avatar piotrmocko piotrmocko - close - 27 May 2014
avatar piotrmocko piotrmocko - reference | - 27 May 14

Add a Comment

Login with GitHub to post a comment