Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [JavaScript]Przeładowanie strony po wysłaniu formularza enterem
mlody69
post
Post #1





Grupa: Zarejestrowani
Postów: 183
Pomógł: 0
Dołączył: 18.05.2009

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


Witam,
mam problem z formularzem, który wysyła dane ajaxem na zewnętrzny serwer. Mianowicie po wciśnieciu entera strona jest przeładowywana lecz po kliknięciu buttona submit jest w porzadku (formularz znika, pojawia się inna treść).
Dodalem opcję preventDefault() lecz to nic nie pomogło. Mój kod wygląda następująco:
  1. $("#u_1d_1").click(function(e) {
  2. e.preventDefault();
  3.  
  4. $.ajax({
  5. type: "POST",
  6. url: "",
  7. dataType : 'json',
  8. data: {
  9. //dane
  10. },
  11. success : function(json) {
  12. status = json['status'];
  13. msg = json['message'];
  14. if(status == '1')
  15. {
  16. //1
  17. } else {
  18. //22
  19.  
  20. }
  21. },
  22. error:function(xhr, status, error) {
  23. var err = eval("(" + xhr.responseText + ")");
  24. alert(err.Message);
  25. }
  26.  
  27. });
  28. return false;
  29. });
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
aras785
post
Post #2





Grupa: Zarejestrowani
Postów: 859
Pomógł: 177
Dołączył: 29.10.2009

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


to może tak:
  1. $(document).ready(function(e){
  2. $(".test").click(function(e) {
  3. e.preventDefault();
  4. alert('Test');
  5. return false;
  6. });
  7. });
Go to the top of the page
+Quote Post

Posty w temacie


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: 9.10.2025 - 23:19