Bug Tracker

Modify

Ticket #4448 (closed bug: invalid)

Opened 4 years ago

Last modified 15 months ago

$.getJSON() and append() link tags <a href>demo</a> sometimes is wrong

Reported by: opengloves Owned by:
Priority: minor Milestone: 1.4
Component: data Version: 1.3.2
Keywords: json and appden link tag Cc:
Blocking: Blocked by:

Description

Good day! I use jquery-1.3.2.min.js. I want append some link tags in a div, but something is wrong, against my expect. some links are right, like this: <a href=" http://www.demo.com/123">demo</a> but some are: <a href=" http://www.demo.com/123"/>demo and these wrong tags was different is Firefox and IE 7. For example such function:

json data:[{"linkKey":"http::www.demo.com/123","linkValue":"demo"}]

html: <div id="site"></div> <div><a id="home">show</a></div>

$("#home").click(function(){

$.getJSON("demo.jsp",

function(json){

$.each(json,function(i){ $("#site").append("<span><a href="+json[i].linkKey+">"+json[i].linkValue+"</a></span>");});});});

To fix this, I have to change the function like this: function(json){

$.each(json,function(i){

n = i+1; $("site").append("<span><a id=id"+n+">"+json[i].linkValue+"</a></span>"); $("#id"+n).attr("href",json[i].linkKey);

});}

but this isn't suitable, I think.

Change History

comment:1 Changed 4 years ago by dmethvin

  • Status changed from new to closed
  • Resolution set to invalid

Your href attribute is not quoted in the HTML you generate, so it is being mis-parsed in some cases. Nothing jQuery can do about invalid HTML...

comment:2 Changed 4 years ago by opengloves

Thank you for your response. I quoted href attribute like this:

$("#site").append("<span><a href=\""+json[i].linkKey+"\">"+json[i].linkValue+"</a></span>");

and it works right. thank you very much.

comment:3 Changed 4 years ago by opengloves

huh..... Firefox 3 works right,but in IE 7 still have some wrong link tags.

comment:4 Changed 4 years ago by opengloves

I thought this is sth. wrong in others libs. thanks again.

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.