Hello everyboy,
I have the following problem
I have a function which shows me the content of a div element
when I start another function in this function it wont work.
here's my code, hope you can help me!
index.php
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
</head>
<body>
<a href="" sort="username2" function="function1">Funktion 1</a><br><br><br>
<a href="" function="function2">Funktion 2</a><br><br>
<div id="content" style="border: 1px solid #b3b2b2; width:200; height:60; background-color:khaki; ">
</div>
</body>
<script type="text/javascript" language="javascript" src="scripts/jquery-1.3.2.min.js"></script>
<script type="text/javascript" language="javascript" src="scripts/jquery.json-1.3.min.js"></script>
<script type="text/javascript" language="javascript" src="scripts/site.js"></script>
</html>
site.js
$.ajaxSetup({url: "core/AJAX.php",type:"POST",dataType:"json"});
$(document).ready(function() {
//Funktion 1
$('a')
.unbind("click")
.click(function(){
if($(this).attr('sort') == null){
var data = $.toJSON({
'method':$(this).attr('function'),
'data':{
'param1':'hallo',
}
});
}
else
{
var data = $.toJSON({
'method':$(this).attr('function'),
'data':{
'param1':'hallo',
'sort':$(this).attr('sort')
}
});
}
$.ajax({
data: {'jsonInput':data},
success: function(AntwortVomServer) {
$("div#content").slideUp("fast", function(){
$(this).html(AntwortVomServer); })
$("div#content").slideDown("slow");
}
})
return false;
})
});
AJAX.php
<?php
$input = $_REQUEST['jsonInput'];
$input = json_decode($input,true);
$method = $input['method'];
$data = $input['data'];
$method($data);
function function1($data){
//...Funktion
$s = '<a href="" function="function2">Funktion 2</a><br><br><br>Hallo. Du hast die Funktion 1 mit dem Parameter '.$data['sort'].' aufgerufen!';
echo json_encode($s);
}
function function2($data){
//...Funktion
$s = "Ich bin die Funktion 2";
echo json_encode($s);
}
?>