Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [AJAX]wyświetlenie jsona na stronie - zwrotnie., jak to wykonać.
casperii
post 27.05.2015, 15:04:54
Post #1





Grupa: Zarejestrowani
Postów: 681
Pomógł: 28
Dołączył: 14.08.2014

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


Mam kod:

Kod
jQuery.fn.delete_school = function (id) {
    var that = $(this);
$('.usun').live('click', function () {
                $.post("/ajax/AjaxUpdateData.php", {
                    remove: id
                }, function (data) {
                    if (data.status == 'success') {
                    
                    $('#info_upd_data').fadeOut(200,function(){
                                        $(this).removeClass('response-waiting').addClass('response-success').text('blabla').fadeIn(200,function(){
                                            setTimeout(function(){
                                                responseMsg.fadeOut(200,function(){
                                                    $(this).removeClass('response-success');
                                                });
                                            },3000);
                                        });
                                    });                  
                    
                    
                    
                    
                       that.parents('#TableShowEducation').remove();
                      
                    } else {
                        $('.stop').click();
                    }
                }, 'json');
});
    });
};



oraz:

  1. if(isset($_POST['remove'])){
  2. $id = intval($_POST['remove']);
  3. if(mysql_query("DELETE FROM `education` WHERE `id` = $id")){
  4.  
  5. $status = "success";
  6. $message = "Szkoła została usunięta.";
  7.  
  8. }
  9. }
  10.  
  11. $data = array(
  12. 'status' => $status,
  13. 'message' => $message
  14. );
  15.  
  16. echo json_encode($data);


Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 6)
Comandeer
post 27.05.2015, 16:00:22
Post #2





Grupa: Zarejestrowani
Postów: 1 268
Pomógł: 254
Dołączył: 11.06.2009
Skąd: Świętochłowice

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


I co nie działa/co chcesz uzyskać?

BTW to $.fn.live jeszcze wgl istnieje? Byłem pewien, że to wywali z jQuery…


--------------------
Go to the top of the page
+Quote Post
casperii
post 27.05.2015, 16:04:20
Post #3





Grupa: Zarejestrowani
Postów: 681
Pomógł: 28
Dołączył: 14.08.2014

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


Cytat(Comandeer @ 27.05.2015, 17:00:22 ) *
I co nie działa/co chcesz uzyskać?

BTW to $.fn.live jeszcze wgl istnieje? Byłem pewien, że to wywali z jQuery…



@Comandeer skoro nie wywaliła konsola błędów to raczej istnieje (?) :-)

A chcę osiągnąć, że jeśli usunęło rekord z bazy pojawił się komunikat ten z php ajaxowego przesyłanego jsonem.

Go to the top of the page
+Quote Post
Comandeer
post 27.05.2015, 16:08:44
Post #4





Grupa: Zarejestrowani
Postów: 1 268
Pomógł: 254
Dołączył: 11.06.2009
Skąd: Świętochłowice

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


Hm…
Kod
$(this).removeClass('response-waiting').addClass('response-success').text('blabla')

na
Kod
$(this).removeClass('response-waiting').addClass('response-success').text(data.message)

? Zamiast tekstu blabla powinno wyświetlić wiadomość. To, co jest przekazywane do success to dane zwrotne z serwera - w przypadku JSON to jest obiekt.

Cytat
skoro nie wywaliła konsola błędów to raczej istnieje (?) :-)

To zapewne - pytanie jakiej wersji jQuery używasz? http://api.jquery.com/live/ → usunięte w 1.9, a obecna wersja to 1.11


--------------------
Go to the top of the page
+Quote Post
casperii
post 27.05.2015, 17:08:21
Post #5





Grupa: Zarejestrowani
Postów: 681
Pomógł: 28
Dołączył: 14.08.2014

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


jQuery - jquery-1.7.1.min.js

Nie wiem czemu ale nie dodaje mi coś tekstu do klasy.

Kod
if (data.status == 'success') {
                        klass = '';
                        var responseMsg = $('#info_upd_data');
                        responseMsg.hide().addClass('response-waiting').text('proszę czekać...').fadeIn(200);
                        
                        responseMsg.fadeOut(200,function(){
                            $(this).removeClass('response-waiting').addClass('response-success').text(data.message).fadeIn(200,function(){
                                setTimeout(function(){
                                    responseMsg.fadeOut(200,function(){
                                        $(this).removeClass(klass);
                                    });
                                },3000);
                            });
                        });                    
                       that.parents('#TableShowEducation').remove();
                      
                    }
Go to the top of the page
+Quote Post
Comandeer
post 27.05.2015, 17:15:45
Post #6





Grupa: Zarejestrowani
Postów: 1 268
Pomógł: 254
Dołączył: 11.06.2009
Skąd: Świętochłowice

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


A co jest w data.message?


--------------------
Go to the top of the page
+Quote Post
casperii
post 27.05.2015, 18:05:15
Post #7





Grupa: Zarejestrowani
Postów: 681
Pomógł: 28
Dołączył: 14.08.2014

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


Cytat(Comandeer @ 27.05.2015, 18:15:45 ) *
A co jest w data.message?


To nie chodziło o nie widzialność data.message tylko co bym nie wpisał w text to nie widziało. Ale kurcze przesłoniłem inną warstwą i dlatego nie widziałem smile.gif
Problem rozwiązany.
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: 14.08.2025 - 02:45