0

first thanks for you help and support!

My question is how can i correctly make a correct output of html code with variables into. I´m working with jquery and jquery.mobile.

I´m getting from a php results of an database seperated with "," and splitted to an javascript array (works) but I´m not able to output these results correctly to an dynamically working list... they have to be in a list with links and jquery look... but it just show me a list with images without the link and without jquery also it don´t stop to load. My internet research don´t gave me the help I need and I don´t know how to solve this. (Because I want to use PhoneGap, I can´t use php in this part)

Here is my code fragment (just the important things):

<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <link rel="stylesheet"  href="css/jquery.mobile-1.2.0.css" />

    <script src="js/jquery.js"></script>

    <script src="js/jquery.mobile-1.2.0.js"></script>


</head>
<body>

                <div id="result">
            <script>
$(document).ready(function(){
    $.post("Test.php",
    {
      q:"Value2ask",
    },
    function(data){

var share=data.split(",");

            if (share.length>=1){
            for(var i = 0; i < share.length; i++)
             {

            var dynlist = dynlist + ('<li><form id="'+share[i]+'" method="POST" action="Next.php" data-ajax="false">'+
            '<input id="id" name="id" value="'+share[i]+'" type="hidden"/> </form>'+
            '<img src="images/pic.png" class="img'+share[i]+'" align="LEFT" width="38" height="38" />'+
            '<a onclick="document.getElementById('+share[i]+').submit();" data-transition="slide" data-ajax="false">&nbsp; '+share[i]+'</a></li>');


            } 
            return document.innerHTML(dynlist);
            } else { 
            var dynlist =   ('<li> <a data-rel="back" data-role="button" data-icon="back" data-ajax="false">No results, click to get back </a></li>');
            return document.innerHTML(dynlist);
            }


    });
});  
</script></div></body></html>

I also tried it with document.write (same result like innerHTML) and some other versions like document.write with every single line .... No positive results ... please help :) Thanks!

EDIT: I get the correct code that I want but it don´t show me the result i want... (the link is not working for example and there is no jQuery in the list ...)

2
  • are you getting any errors ? Commented Mar 4, 2013 at 5:12
  • @EnterJQ no the web-developer console stops at the post command ... Commented Mar 4, 2013 at 5:37

2 Answers 2

0

You have var dynlist in for loop of success response.

correct that with

var dynlist;

for(conditions)
{
    dynlist += "code";
}

and instead of returning return document.innerHTML(dynlist); you can use .html(),.text() or .attr() or .append() jQuery methods to add your dynlist to html DOM.

Example

$(documet).append(dynlist);
$('div#result').append(dynlist);
3
  • doesn't work ... it shows me nearly the same like before ... but thanks for my error that i got the var in my loop... Commented Mar 5, 2013 at 3:57
  • okay i got it so that i got the correct html code in js, and it is also shown. But there the jquery style missing ... it looks like these: jsfiddle.net/hYQm4/32 (but noramlly this list should got a jquery style and also links to click ... Commented Mar 9, 2013 at 23:12
  • Okay I solved it! Where was just the listview refresh missing! Now I got the jquery mobile style but the button doesn't work (no action)... somebody an idea? Commented Mar 11, 2013 at 4:28
0

Okay there was just missing an listview refresh to get the jquery mobile style ... and missing ' for the getElementbyID part. Thanks for the help

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.