jquery post to php

08/07/2014 16:46 FreewayC#1
Hi,

ich möchte gerne den ausgewählten Index eines <select> Elementes über jquery mit "$.post" übermitteln. Der Wert wird richtig ermittelt, aber er wird nicht "richtig" gesendet.

jquery
Code:
$(document).ready(function(){
   $("#classSelect").click(function(){
      $.post("backend.php?action=loadClass",{classname : $("#alleKlassen option:selected" ).text()}); 
   });
});
php
PHP Code:
<?php
        
if(isset($_GET['action'])){
            switch(
$_GET['action']){
            case 
"loadClass":   $value $_POST['classname']; echo $value; break;              
            }
        }
        
?>

Exception:
Notice: Undefined index: classname



Quelle jquery

Code:
$.post( "test.php", { name: "John", time: "2pm" } );
Example: Request the test.php page and send some additional data along (while still ignoring the return results).


freundliche Grüße
08/08/2014 16:56 turk55#2
Quote:
Originally Posted by FreewayC View Post
Hi,

ich möchte gerne den ausgewählten Index eines <select> Elementes über jquery mit "$.post" übermitteln. Der Wert wird richtig ermittelt, aber er wird nicht "richtig" gesendet.

jquery
Code:
$(document).ready(function(){
   $("#classSelect").click(function(){
      $.post("backend.php?action=loadClass",{classname : $("#alleKlassen option:selected" ).text()}); 
   });
});
php
PHP Code:
<?php
        
if(isset($_GET['action'])){
            switch(
$_GET['action']){
            case 
"loadClass":   $value $_POST['classname']; echo $value; break;              
            }
        }
        
?>

Exception:
Notice: Undefined index: classname



Quelle jquery

Code:
$.post( "test.php", { name: "John", time: "2pm" } );
Example: Request the test.php page and send some additional data along (while still ignoring the return results).


freundliche Grüße
I recommend using $.ajax instead:

Code:
$("#classSelect").click(function(){
	$.ajax({
		type: "POST",
		data: $("form#form").serialize(),
		url: "test.php",
		success: function(data){
			// data is the value returned from test.php
		}
	});
	return false;
});