0

The code that sends the string looks like this, is it a json response perhaps?

    $.getJSON(loadUrl, parameters, function (response) {
        callback(response.data);
    })

Does this mean that the response indeed is json? See below screenshot for the actual response given (when using alert(data)):

enter image description here

EDIT: I think that the returned data is indeed json. This is what the console looks like when printing the data returend: enter image description here

EDIT2:

The response was indeed json. I looped it like below:

$(data).each(function(index, element){  
$('#scores').append('<tr><td> '+element[0]+' </td> <td> '+element[1]+' </td></tr>');       
    })
3
  • 2
    Split by commas, take one for the title, take the next for the number, output row, repeat. Commented Feb 25, 2013 at 9:32
  • It's hard to tell what the question is. I can't see any reference to HTML table in the question... Commented Feb 25, 2013 at 9:32
  • @JakubKonecki I see your point. Couldn't think of a better title. Commented Feb 25, 2013 at 9:35

2 Answers 2

1

Split the string as you done before and convert it to jSon object. Then you can create table from it easily..

ref : jQuery function to create table using JSON data

Sign up to request clarification or add additional context in comments.

2 Comments

have a look to fiddler link provided in above post
The example in the link worked.
1

As deceze said you should split the string by commas

var str="/startpage,147,/contact,97";
var n=str.split(","); //['/startpage','147',/contact','97' ]

Then loop the array to create the html

for(i=0; i < n.length; i+=2)
{
  var title = n[i];
  var value = n[i+1];
}

Please be aware this is a very dirty solution. If you have control over the string's origin, you should consider changing to another format, such as JSON or XML

1 Comment

I've updated the post, some of the code handling the response is calling json.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.