0

I have a script that returns data as json and displays it inside an alert box. What I want to do is display each line of the data as a list.

I have (with help) managed to produce some code that performs this task only if there data has one object per row using the code below:

<ul><li>'+result.join('</li><li>')+'</ul>'

But, if the returned json has multiple objects per row I get the following error: Uncaught TypeError: result[3].join is not a function at Object.success.

The code that is causing this error is:

<ul><li>'+result[0]+'<br/>Room: '+result[1]+'<br/>Between: '+result[2]+' and '+result[3].join('</li><li>')+'</ul>

Can anyone see where I have gone wrong and if possible provide a way in which the returned json data can be displayed as list items. The complete ajax code is:

$.alert({
  type: 'red',
  title: 'Error: Room booking period overlap ',
  content: 'Client: <ul><li>'+result[0]+'<br/>Room: '+result[1]+'<br/>Between: '+result[2]+' and '+result[3].join('</li><li>')+'</ul>',
  'fa fa-rocket',<ul><li>'+result.join('</li><li>')+'</ul>'
   animation: 'zoom',
   boxWidth: '50%',
   closeAnimation: 'zoom',
   buttons: { 
     Close: function() {
       text: 'Close'
     }
  }
}) 

Many thanks in advance for your time.

DCJones
  • 3,121
  • 5
  • 31
  • 53
  • 1
    What does the `result` object look like, when you have multiple items. You have to iterate over them – Velimir Tchatchevsky Sep 18 '18 at 17:41
  • @Velimir Tchatchevsky hi and thanks for your help. The data looks like the:["IAAF","Watt Suite","16-09-2018 10:00","18-09-2018 15:00","EXBHX","Bolton Suite","18-09-2018 08:01","18-09-2018 12:00","EXBHX","Watt Suite","18-09-2018 08:01","18-09-2018 12:00"] – DCJones Sep 18 '18 at 17:43
  • They are all in the same object, I guess you'd have to split that up yourself and use the function you have on each new array, to create the desired html. This might help you with the splitting -> https://stackoverflow.com/questions/11318680/split-array-into-chunks-of-n-length – Velimir Tchatchevsky Sep 18 '18 at 17:50

0 Answers0