0

I want get the data coming in JSON through a php url using JAVASCRIPT and displaying that data in JQuery mobile "li" tag(it'll be a complete category list) but using the code given below isn't displaying anthing. I'll be very thankful, I am stuck in this thing from last 8 hours.

<script>
                  var session_id = localStorage.getItem('session_id');
                  var user_id = localStorage.getItem('user_id');  
            $(document).ready(function() {
             //$('#output').html('somestuff');

                $('#loginForm').submit(function() {
                    //$('#output').html('Connecting....');
                    var postTo = 'http://localhost/categories.php';
                    //alert(postTo);
                    $.post(postTo,{userid: $('[name=user_id]').val() ,   sessionid:  $('[name=session_id]').val()} , 
                        function(data) {

                            if(data.status == 'true') {

                                $("#userdata tbody").html("");
                                $.getJSON(postTo,function(data){
                                $.each(data.members, function(i,user){
                                var tblRow =
                                "<li data-theme="e">"
                                 +"<a data-transition="flow" href="">"+user.category+"</a>"
                                  +"</li>";
                                $(tblRow).appendTo("#userdata tbody");
                                });
                                });


                            } else {

                                window.open("./MyApp.html","_self");
                            }

                        },'json');

                    return false;
                });
            });
            </script>
2
  • put a debugger after function(data) { and check what it returns in data as well as check your console if der is anything wrong Commented Apr 24, 2017 at 11:47
  • Can I see your complete code ? (e.g html and categories.php) Commented Apr 24, 2017 at 11:56

2 Answers 2

0

You have a syntax error at +"<a data-transition="flow" href="">"+. "flow" is outside quotes (so it's counted as a var, but you didn't used "+") so you should only put single quotes before and after "flow". Same goes for the href.

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

Comments

0

this $(tblRow).appendTo("#userdata tbody"); should be

something like

$("#userdata tbody").appendTo(tblRow);

Read more here about appending content to element

and

 var tblRow ="<li data-theme="e">"  
                             +"<a data-transition="flow" href="">"+user.category+"</a>"
                             +"</li>";

change it into

 var tblRow ='<li data-theme="e">' 
                             +'<a data-transition="flow" href="">'+user.category+'</a>'
                             +'</li>';

Check your console what it says to precise on your errors and where exactly it fails.

Refer this question for writing html with jQuery

1 Comment

Check your console for errors and tell us exactly where it fails?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.