views:

138

answers:

5

EDIT: This isn't happening because of the ajax call. I changed it to use a value from a TinyMCE component for fun and I get the same thing.

content = tinyMCE.get('cComponent').getContent(); //content at this point is <p>test</p>
valueToDisplay = content;

If I do:

jQuery(selector).html(valueToDisplay);

I get:

<p><a xmlns="http://www.w3.org/1999/xhtml"&gt;test&lt;/a&gt;&lt;/p&gt;

Has anyone ever seen this before using Firefox 3.6.10 and jQuery 1.4.2, I am trying to change a link text using the result from a jQuery ajax call.

I get the result expected from the ajax call:

function getValueToDisplay(fieldType){
    var returnValue;
    jQuery.ajax({
        type: "GET",
        url: "index.cfm",
        async:false, 
        data: "fieldtype="+fieldType,
        success:function(response){
            returnValue = response;
    }                   
    });
    return returnValue;
   }

If I check the value at this point I get the expected value

console.log(returnValue) //output this --> <p>Passport Photo</p>

However when I use jQuery(selector).html to insert it inside of an existing anchor

I get:

<p><a xmlns="http://www.w3.org/1999/xhtml"&gt;Passport Photo</a></p>

I have been trying to figure out where that xmlns anchor is added but can't narrow it down to anything specific.

EDIT: I have tried forcing dataType:"html" in the ajax call...no change.

A: 

This is happening because in your <html> you declared a XML Namespace (xmlns). If the xmlns anchor is not breaking anything, just leave it there.

Also, don't use async:false, make a callback function to be called on success.

Rocket
Good point but I am not using any namepsace in the html tag for this app. This is the header - <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html debug="true">
jfrobishow
Firefox probably is adding it for you because there isn't one there.<html xmlns="http://www.w3.org/1999/xhtml">
dave
@dave if I read the spec correctly the xmlns is only required if the document is xhtml. This should tell the browser it isn't no? <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> based on http://www.w3schools.com/tags/tag_html.asp and http://www.w3schools.com/tags/tag_doctype.asp
jfrobishow
A: 
jfrobishow
A: 

Try changing dataType in your ajax call to "text"

dave
@dave it's not coming from the ajax request. I was able to reproduce it with values accessed directly from TinyMCE. It's not constant, but appears to be coming from jQuery.html(string)
jfrobishow
+1  A: 

Your selector represents something that is, or is in an a tag.

A much more minimal version of your problem would be:

html:

<a id="test"></a>

js:

$('#test').html('<p>test</p>');

result:

<a id="test"><p><a xmlns="http://www.w3.org/1999/xhtml"&gt;test&lt;/a&gt;&lt;/p&gt;&lt;/a&gt;

Change things around so you aren't putting p tags in an a tag, or do the following:

$('#test').empty().append('<p>test</p>');
Conley Owens
A: 

Hey!

I have the same problem with JQuery 1.4.3 & FF 3.x, if I insert something with ".html()" I get an extra Div wrapper with an XLMNS attribute. If I use ".append()", everything is ok…

Benziman