Question

i wants to show custom message in confirmation box like

var response=confirm(Are you sure you want to select these times?

1)3a.m to 4a.m

2)8a.m to 9a.m

so on...)

this data i am getting from php page in json format in multidimensional array on ajax success and i wants to show this json data by iterating, as message. data i am getting w'll be like [{'start_time':3a.m,'end_time':4a.m}{'start_time':8a.m,'end_time':9a.m}....]

Can anyone help me in this.

Thanks in advance

Was it helpful?

Solution

var data = [{'start_time':'3a.m','end_time':'4a.m'},{'start_time':'8a.m','end_time':'9a.m'}];

var alertText = "Are you sure you want to select these times?\n"
for(var i in data) {
    alertText += data[i].start_time+ " to "+ data[i].end_time +"\n";
}
var response = confirm( alertText );

You can do this. This is show alert as you want.I give you only example using your data.

OTHER TIPS

You can use a templating engine like handlebars .

  1. you get the data from sever using ajax which you already done that.

  2. you define a template by handlebar like

    <script id="unit-template" type="text/x-handlebars-template">
       <div id="urDataWillExapndedHere">
            <ul>
             {{#each data}}
              <li>
                Time:      '{{this.date}}'               
              </li>
             {{/each}}
             </ul>
          </div>
     </script>
    

3.you compile the script put the data to template and get an html result back.

4.you put your html using innderHtml() or jquery html() or whatever your like to an html element

5.show that element using confirmation dialog

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top