0

I'm trying to jquery to return php value inside div I'm using .html() but I did get Uncaught SyntaxError: Unexpected identifier my html code is :

<script>
        $( document ).ready(function()
            $('#post-msg-<?= $divId ?>').html(`<?= \humhub\actions\TextFormatAction::text_html($model->message) ?>`);
        });
    </script>

on inspect element I see my php code is :

$( document ).ready(function() {
            $('#post-msg-e369853df766fa44e1ed0ff613f563bd').html('<p></p><img src="http://127.0.0.1/index.php?file=d2dd907d-bfd4-40ab-832f-bd8c161fd60e+" alt="" title="" />
<p> 
            <div class="div-div">
                <div>
                    <div class="div-title-description">
                        <h2>
                            <span class="div-title">Title-text</span>
                        </h2>
                        <p class="div-description">Description - text </p>
                    </div>                
                </div>
            </div>
        </p>
');
        });
3
  • .html('<p></p><img src="http://127.0.0.1/index.php?file=d2dd907d-bfd4-40ab-832f-bd8c161fd60e+" alt="" title="" /> seems to be missing '); at the end Commented Apr 14, 2022 at 6:00
  • @Bravo I did copy past to what I get <p></p><img src="http://127.0.0.1/index.php?file=d2dd907d-bfd4-40ab-832f-bd8c161fd60e+" alt="" title="" /> <p> <div class="div-div"> <div> <div class="div-title-description"> <h2> <span class="div-title">Title-text</span> </h2> <p class="div-description">Description - text </p> </div> </div> </div> </p> Commented Apr 14, 2022 at 6:03
  • @Bravo is what my php function return Commented Apr 14, 2022 at 6:04

1 Answer 1

1

This is the way it should look like to work. You should have no line breaks in HTML from the html function.

<html>
<head>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
</head>
<body>


<script>

$( document ).ready(function() {
            $('#post-msg-e369853df766fa44e1ed0ff613f563bd').html('<p></p><img src="http://127.0.0.1/index.php?file=d2dd907d-bfd4-40ab-832f-bd8c161fd60e+" alt="" title="" /><p><div class="div-div"><div><div class="div-title-description"> <h2> <span class="div-title">Title-text</span> </h2> <p class="div-description">Description - text </p>  </div> </div></div></p>');
        });
        
</script>
</body>
<div id="post-msg-e369853df766fa44e1ed0ff613f563bd">

</div>
        </html>

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

2 Comments

I have a php function code inside html()
Yes, remove the line breaks. What is so complicated? html(<?= str_replace(array("\r", "\n"), '',\humhub\actions\TextFormatAction::text_html($model->message)) ?>);

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.