Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> Javascript error: SyntaxError: Unexpected token < in JSON at position 2
maxerxxl
post 15.07.2017, 23:54:52
Post #1





Grupa: Zarejestrowani
Postów: 19
Pomógł: 0
Dołączył: 29.03.2014

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


Cześć.

Mam pewien problem otóż co chwile pojawia mi się błąd i nie wiem jak go naprawić.

Kod
exit(
    json_encode(array('success' => false, 'error' => 'You must login to access the redeem.'))
);


Kod
function redeem(){
    var code = $("#promo_code").val();
    $.ajax({
        url:"/pages/config/promo_code.php?code="+code,

        success:function(data)
        {
            try
            {
                data = JSON.parse(data);
                console.log(data);

                if (data.success)
                {
                    bootbox.alert("Success! You've received "+data.credits+" credits.");                    
                }

                else
                {
                    bootbox.alert(data.error);
                }
            }

            catch (error)
            {
                bootbox.alert("Javascript error: "+error);
            }
        },

        error:function(error)
        {
            bootbox.alert("AJAX error: "+error);
        }
    });
}
Go to the top of the page
+Quote Post
viking
post 16.07.2017, 04:10:12
Post #2





Grupa: Zarejestrowani
Postów: 6 365
Pomógł: 1114
Dołączył: 30.08.2006

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


Konsola i sprawdź co dostajesz w odpowiedzi. Pewnie html.


--------------------
Go to the top of the page
+Quote Post
maxerxxl
post 16.07.2017, 12:38:26
Post #3





Grupa: Zarejestrowani
Postów: 19
Pomógł: 0
Dołączył: 29.03.2014

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


Nic nie dostaje.
Go to the top of the page
+Quote Post
viking
post 16.07.2017, 13:33:21
Post #4





Grupa: Zarejestrowani
Postów: 6 365
Pomógł: 1114
Dołączył: 30.08.2006

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


Skoro wysyłasz żądanie to i dostajesz odpowiedz. Nie ściemniaj.


--------------------
Go to the top of the page
+Quote Post
maxerxxl
post 16.07.2017, 15:03:49
Post #5





Grupa: Zarejestrowani
Postów: 19
Pomógł: 0
Dołączył: 29.03.2014

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


Jednak miałem wyłączoną obsługę błędów. Po włączeniu pojawiły się błędy w pliku. Naprawiłem i działa. Dziękuję za pomoc smile.gif
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: 17.04.2024 - 00:50