Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> Błąd przy wykonywaniu ajax'a
Inferno211
post 15.10.2015, 10:55:01
Post #1





Grupa: Zarejestrowani
Postów: 11
Pomógł: 0
Dołączył: 16.04.2012

Ostrzeżenie: (0%)
-----


Witajcie, robię system komentarzy i wywala mi błąd, przy dodawania komentarza (w konsoli)... Jest to taki oto błąd:
Kod
Uncaught Error: Syntax error, unrecognized expression: <li>
                                                    <div class="comment-wrapper">
                                                        <div class="comment-author"><img src="img/default-avatar.jpg" alt="User Name"> Inferno</div>
                                                        <p>
                                                            aasdasdasdasd
                                                        </p>
                                                        <div class="comment-actions">
                                                            <span class="comment-date">15 Oct 2015</span>
                                                            <a href="#" data-toggle="tooltip" data-original-title="+1" class="show-tooltip"><i class="glyphicon glyphicon-thumbs-up"></i></a>
                                                            <a href="#" data-toggle="tooltip" data-original-title="-1" class="show-tooltip"><i class="glyphicon glyphicon-thumbs-down"></i></a>
                                                            <span class="label label-success">+8</span>
                                                        </div>
                                                    </div>
                                                </li>


Szukałem na necie co zrobić, ale nic nie ma :/

Oto plik js:
  1. $(document).ready(function(){
  2. $('#submit_post').click(function(){
  3. var uid = 1;//$_SESSION['id'].val();
  4. var comment = $('#postbox').val();
  5. var pid = 7;//$_GET['post'].val(); //static post id
  6.  
  7. if (!comment.trim()) {
  8. //alert('Wpisz komentarz!');
  9. $('#komentarzError').modal('show');
  10. return false;
  11. }
  12.  
  13. $.ajax({
  14. url:'/inc/functions/add-comment.php',
  15. type:'post',
  16. //data:'uid='+uid+'&comment='+comment+'&pid='+pid,
  17. data : {uid: uid, comment: comment, pid: pid},
  18. success:function(data){
  19. if(! data ){
  20. alert('Coś poszło nie tak!');
  21. return false;
  22. }
  23. $(data).hide().prependTo("#comment_thread").fadeIn(1000);
  24. //reset input boxes
  25. $('#postbox').val('');
  26. }
  27. });
  28. });
  29. });


A oto plik add-comment.php:

  1. <?php
  2. //ini_set( 'display_errors', 'On' );
  3. //error_reporting( E_ALL );
  4. define('INCLUDE_CHECK',true);
  5. require('dbconnect.php');
  6. require('functions.php');
  7. $uid = $_POST['uid'];
  8. $comment = $_POST['comment'];
  9. $pid = $_POST['pid'];
  10. $comment = mysql_real_escape_string($comment);
  11. /*$uid = $_GET['uid'];
  12. $comment = $_GET['comment'];
  13. $pid = $_GET['pid'];*/
  14.  
  15. $query = "INSERT INTO comments VALUES('','$uid','$comment','$pid',NOW()) ";
  16. //echo $query;
  17. mysql_query($query);
  18.  
  19. $html = '';
  20. if( mysql_insert_id() ){
  21.  
  22. $html = ' <li>
  23. <div class="comment-wrapper">
  24. <div class="comment-author"><img src="img/default-avatar.jpg" alt="User Name"> '.getNameByID($uid).'</div>
  25. <p>
  26. '.$comment.'
  27. </p>
  28. <div class="comment-actions">
  29. <span class="comment-date">'.date("d M Y",time()).'</span>
  30. <a href="#" data-toggle="tooltip" data-original-title="+1" class="show-tooltip"><i class="glyphicon glyphicon-thumbs-up"></i></a>
  31. <a href="#" data-toggle="tooltip" data-original-title="-1" class="show-tooltip"><i class="glyphicon glyphicon-thumbs-down"></i></a>
  32. <span class="label label-success">+8</span>
  33. </div>
  34. </div>
  35. </li>';
  36. }
  37. echo $html;
  38. ?>


Co jest nie tak? Proszę o szybką pomoc smile.gif
Go to the top of the page
+Quote Post
Pyton_000
post 15.10.2015, 11:06:22
Post #2





Grupa: Zarejestrowani
Postów: 8 068
Pomógł: 1414
Dołączył: 26.10.2005

Ostrzeżenie: (0%)
-----


Ustaw w Ajax dataType: 'html'
Go to the top of the page
+Quote Post
Inferno211
post 15.10.2015, 11:49:44
Post #3





Grupa: Zarejestrowani
Postów: 11
Pomógł: 0
Dołączył: 16.04.2012

Ostrzeżenie: (0%)
-----


nadal to samo, zrobiłem tak:

Kod
            $(document).ready(function(){
                $('#submit_post').click(function(){
                    var    uid         =    1;//$_SESSION['id'].val();
                    var comment        =    $('#postbox').val();
                    var pid            =    7;//$_GET['post'].val(); //static post id

                    if (!comment.trim()) {
                        //alert('Wpisz komentarz!');
                        $('#komentarzError').modal('show');
                        return false;
                    }
                    
                    $.ajax({
                        url:'/inc/functions/add-comment.php',
                        type:'post',
                        dataType:'html',
                        //data:'uid='+uid+'&comment='+comment+'&pid='+pid,
                        data : {uid: uid, comment: comment, pid: pid},
                        success:function(data){
                            if(! data ){
                                alert('Coś poszło nie tak!');
                                return false;
                            }
                            $(data).hide().prependTo("#comment_thread").fadeIn(1000);
                            //reset input boxes
                            $('#postbox').val('');
                        }
                    });
                });
            });


a błąd:

Kod
Uncaught Error: Syntax error, unrecognized expression: <li>
                                                    <div class="comment-wrapper">
                                                        <div class="comment-author"><img src="img/default-avatar.jpg" alt="User Name"> Inferno</div>
                                                        <p>
                                                            dasdasd
                                                        </p>
                                                        <div class="comment-actions">
                                                            <span class="comment-date">15 Oct 2015</span>
                                                            <a href="#" data-toggle="tooltip" data-original-title="+1" class="show-tooltip"><i class="glyphicon glyphicon-thumbs-up"></i></a>
                                                            <a href="#" data-toggle="tooltip" data-original-title="-1" class="show-tooltip"><i class="glyphicon glyphicon-thumbs-down"></i></a>
                                                            <span class="label label-success">+8</span>
                                                        </div>
                                                    </div>
                                                </li>
Go to the top of the page
+Quote Post
Pyton_000
post 15.10.2015, 11:58:12
Post #4





Grupa: Zarejestrowani
Postów: 8 068
Pomógł: 1414
Dołączył: 26.10.2005

Ostrzeżenie: (0%)
-----


$(data).hide().prependTo("#comment_thread").fadeIn(1000); ...

Próbujesz ukryć to co dostałeś z ajax.

$('#comment_thread').prepend(data).fadeIn(1000);
Go to the top of the page
+Quote Post
Inferno211
post 15.10.2015, 12:11:05
Post #5





Grupa: Zarejestrowani
Postów: 11
Pomógł: 0
Dołączył: 16.04.2012

Ostrzeżenie: (0%)
-----


Zmieniłem, ale nadal mam ten błąd sad.gif oto mój plik js

Kod
            $(document).ready(function(){
                $('#submit_post').click(function(){
                    var    uid         =    1;//$_SESSION['id'].val();
                    var comment        =    $('#postbox').val();
                    var pid            =    6;//$_GET['post'].val(); //static post id

                    if (!comment.trim()) {
                        //alert('Wpisz komentarz!');
                        $('#komentarzError').modal('show');
                        return false;
                    }
                    
                    $.ajax({
                        url:'/inc/functions/add-comment.php',
                        type:'post',
                        dataType:'html',
                        //data:'uid='+uid+'&comment='+comment+'&pid='+pid,
                        data : {uid: uid, comment: comment, pid: pid},
                        success:function(data){
                            if(! data ){
                                alert('Coś poszło nie tak!');
                                return false;
                            }
                            //$(data).hide().prependTo("#comment_thread").fadeIn(1000);
                            $('#comment_thread').prepend(data).fadeIn(1000);
                            //reset input boxes
                            $('#postbox').val('');
                        }
                    });
                });
            });



@EDIT

Zapomniałem uploadować aktualną wersję js, mój błąd haha.gif

Ten post edytował Inferno211 15.10.2015, 12:16:10
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 20.04.2024 - 01:31