Possible Fix:
I've encountered this before. I managed to follow the stack trace back to a call of jQuery's .replaceWith() method inside of a framework file:
framework/admin/javascript/LeftAndMain.js
... look for the "handleAjaxResponse" closure, around line 433.
The line that reads as follows:
// Replace panel completely (we need to override the "layout" attribute, so can't replace the child instead)
contentEl.replaceWith(newContentEl);
...is the culprit (in my case). The jQuery .replaceWith() function expects one of three parameters:
- An HTML string
- A jQuery wrapped element.
- A raw HTML DOM node.
...I was getting a jQuery wrapped object, but the object inside WAS NOT AN ELEMENT. It was a JSON object, which had a property named "CurrentForm" that contained an HTML string representation of the form. (Thanks, inventor of console.log()!)
I changed the code to the following:
// Replace panel completely (we need to override the "layout" attribute, so can't replace the child instead)
//contentEl.replaceWith(newContentEl); // ...original line of code
if (newContentEl[0] && newContentEl[0].CurrentForm) // Check to see if this is some kind of special jQuery wrapped object.
{
contentEl.replaceWith( newContentEl[0].CurrentForm ); // Grab that HTML string that's inside the object, use it instead.
} else {
// handle things as usual...
contentEl.replaceWith(newContentEl);
}
... Hope this helps. :-)
- Alex Albino
UPDATE: It turns out, this issue is a little higher up the stack. IGNORE THE PREVIOUS EDITS. JUST CHANGE THE FOLLOWING!!!
In the 'handleAjaxResponse' handler in framework/admin/javascript/LeftAndMain.js, change:
if(xhr.getResponseHeader('Content-Type') == 'text/json') {
...to
if(xhr.getResponseHeader('Content-Type').match( /^text\/json/, 'text/json' ) ) {
...and see if that works. It turns out that if you have the PHP.ini directive 'default_charset' set to something, your server will NOT reply with 'application/json' in the xhr header, but instead respond with 'application/json;charset=XXX' ...where XXX is the character set you have on your server. THEREFORE, the if-statement will fail when using the == operator ...we should instead use a regex match, as per the updated code snippet above.