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
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
Post #2





Grupa: Zarejestrowani
Postów: 6 380
Pomógł: 1116
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
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
Post #4





Grupa: Zarejestrowani
Postów: 6 380
Pomógł: 1116
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
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 (IMG:style_emoticons/default/smile.gif)
Go to the top of the page
+Quote Post

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

 



RSS Aktualny czas: 22.08.2025 - 22:17