2016-03-27 10 views
-2

Ich bin mir nicht sicher, ob ich es richtig mache. Ich gebe eine URL für ajax 'GET' Anfrage und URL hat die einige Abfrage-Parameter (? Abc = 'a'). Aber wenn ich console.log (response) in Erfolg: function (response) {console.log (Antwort)}. Die Antwort enthält keine abc-Wert.Was ist die Antwort im Erfolg: Funktion (Antwort) in Ajax

+2

Könnten Sie den Code in Frage geben? Es ist viel einfacher zu beantworten, wenn wir einen Code haben, den wir uns ansehen können. –

+0

Warum sollten Sie erwarten, dass die ** Antwort ** ** Anfrageparameter enthält? –

+0

* "Was ist die Antwort im Erfolg: Funktion (Antwort) in AJAX" * [Dies ist in der Dokumentation sehr gut erklärt] (http://api.jquery.com/jQuery.ajax). –

Antwort

0

Ich will Ihnen ein Beispiel mit AJAX auf der Konsole Daten zeigen:

<script type="text/javascript"> 
    //this the DOM 
    $(function(){ 

     $('body').on('click', '.action_button', function() { 
      $x = { 
       key:'show', 
       values:$('.values').val() 
      }; $.post('ajax.php', $x, function(response) { 
       console.log(response); 
      }); 
     }); 

    }); 
</script> 


<?php 
    //your php file in ajax.php (another file) 
    $key = $_POST['key']; 

    switch ($key) : 
     case 'show' : 
      $values = $_POST['values']; 
      echo $values; 
     break; 
    endswitch; 
?> 

HTML IST HIER

<input type="text" class="values" placeholder="Give me some values"> 
<input type="button" class="action_button" value="Click me for show the links">