Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [AJAX]ajax nie dziala
benzulli
post
Post #1





Grupa: Zarejestrowani
Postów: 112
Pomógł: 0
Dołączył: 3.07.2013

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


Kod
var menuId = "asd";
$(document).ready(function() {
        $.ajax({
          url: "kanwa.php",
          type: "POST",
          data: {id : menuId},
          dataType: "html"
        });
        });
        alert(<?php echo $_POST['id']; ?>);


Post zwraca pustą zmienną

Ten post edytował benzulli 29.11.2015, 17:33:46
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
com
post
Post #2





Grupa: Zarejestrowani
Postów: 3 034
Pomógł: 366
Dołączył: 24.05.2012

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


Proszę działający przykład
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8" />
  5. <script src="http://code.jquery.com/jquery-2.1.4.min.js"></script>
  6. $(function() {
  7. var menuId = "asd";
  8. $.getJSON('ajax.php', {input: ""+menuId+""}, function(data) {
  9.  
  10. $('input[name="id"]').val(data.id);
  11. });
  12. });
  13. </script>
  14. </head>
  15. <body>
  16. <input type="text" name="id" value="asdasdas">
  17. <input type="submit">
  18. </body>
  19. </html>


  1. <?php
  2. $a = (object) [];
  3. $a->id = $_GET['input'];
  4. echo json_encode($a);
  5. ?>




problem rozwiązany (IMG:style_emoticons/default/smile.gif)
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: 15.10.2025 - 00:05