Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> AJAX i 400 Bad Request, Your browser sent a request that this server could not understand.
bor1904
post
Post #1





Grupa: Zarejestrowani
Postów: 131
Pomógł: 1
Dołączył: 15.10.2009
Skąd: gdańsk

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


Witam,
Chciałem wykorzystać odrobine AJAXA i już straciłem kilka godzin.

Jest formularz:
  1. <form onsubmit="return send()" name="contact_form" method="post" action="">
  2.  
  3. <label for="author">Imie i nazwisko:</label> <input type="text" id="name" name="name" />
  4. <div class="cleaner_h10"></div>
  5. <label for="email">Email:</label> <input type="text" id="email" name="email" />
  6. <div class="cleaner_h10"></div>
  7.  
  8. <label for="url">Telefon:</label> <input type="text" name="phone" id="url" />
  9. <div class="cleaner_h10"></div>
  10.  
  11. <label for="text">Wiadomość:</label> <textarea id="text" name="enquiry" rows="0" cols="0"></textarea>
  12. <div class="cleaner_h10"></div>
  13.  
  14. <input type="submit" value=" Wyślij"/>
  15.  
  16. </form>



Kod JS w head:

  1.  
  2. <script type="text/javascript">
  3. function send()
  4. {
  5.  
  6. var xmlhttp;
  7. if (window.XMLHttpRequest)
  8. {// code for IE7+, Firefox, Chrome, Opera, Safari
  9. xmlhttp=new XMLHttpRequest();
  10. }
  11. else
  12. {// code for IE6, IE5
  13. xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  14. }
  15.  
  16. xmlhttp.onreadystatechange=function()
  17. {
  18. if (xmlhttp.readyState==4 )
  19. {
  20. alert(xmlhttp.responseText);
  21.  
  22. }
  23. }
  24. xmlhttp.open("POST","test.php",false);
  25. xmlhttp.send();
  26. }
  27.  
  28.  


Skrypt test.php:
  1. <?php echo "fsdfs"; ?>





Po kliknięciu wyślij pojawia sie message boź z treścią pochodzącą z php, a po kliknięciu OK wyskakuje
"400 Bad Request
Your browser sent a request that this server could not understand. "



Co robie nie tak?

PS: z wielu tutków przeklejałem (w tym z W3Schools) i nic ....

Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
mambus
post
Post #2





Grupa: Zarejestrowani
Postów: 53
Pomógł: 0
Dołączył: 30.11.2010

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


Ah, no coż. Próbowałem uniknąć JSONa, ale okej, wydłubałem coś takiego:

  1. http_request.onreadystatechange = function() {
  2. $('#info_text_title').html(http_request.responseText);
  3.  
  4. $.getJSON("/includes/ajax_api.php?id="+id,{id:id},function(data) {
  5.  
  6.  
  7. for(var i in data) {
  8. alert(data[i].product_link + '<br/>');
  9. }
  10. });
  11.  
  12. //var infoArray = eval(http_request.responseText);
  13. //alert(infoArray[product_name]);
  14. };


po stronie PHP JSON encoduje się okej bo wyprintowałem i jest właściwy format.

  1. (...)
  2.  
  3. $array=json_encode($row);


Problem jednak pojawia się taki, że kiedy alertuje pętle w jquery to ciągle jest undefined. Czy problem jest z przekazywaniem zmiennej id ? Eh.

EDIT:

Po wyrzuceniu .product_link jest okej - alertuje każdy element. Nie wiem natomiast jak się odnieść np do jednego z nich... np product_link


Ten post edytował mambus 5.09.2012, 11:06:04
Go to the top of the page
+Quote Post

Posty w temacie


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 Aktualny czas: 20.08.2025 - 15:49