i've got some problem
my html: http://jsfiddle.net/dHdnb/
my jquery:
$(".header_nav li a").click(function(){
var href = this.href;
$.ajax({
url: 'dynamic.php',
type: 'POST',
data: { target: href },
success: setTimeout(function(){
$.ajax({
url: 'dynamic.php',
dataType: 'html',
data: { target: href},
success: function(data) {
$(".container").html(data)
}
})
}, 1000)
})
here is my php code:
<?php
$target = $_POST["target"];
echo $target;
function home(){
echo $target;
// some command
}
switch($target) {
case "home": home();
break;
// and so on
default;
}
$target = isset($_POST['target']) ? $_POST['target'] : 'default_target_value';
echo $target;
echo "Test ajax";
?>
lets me explain this, if the user click the button on those list
then, it will post the target variable into the server
then, the server will process the request and launch a function
finally, when the ajax process success, it will load the data from the server into the container div
my question is, why it's gave me an error like this?
"Notice: Undefined index: target in xxx.php on line 7"
i know there must be something wrong with my data on my ajax,
but i don't know where's my mistakes
please help me :)
when i'm debug it with charles, the ajax send the data with text string like this
my POST request raw:
POST /xxx/dynamic.php HTTP/1.1
Host xxx
Content-Length 67
Accept /
Origin http ://xxx
X-Requested-With XMLHttpRequest
User-Agent xx Content-Type application/x-www-form-urlencoded; charset=UTF-8
Referer http:/xxx.php
Accept-Encoding gzip,deflate,sdch
Accept-Language en-US,en;q=0.8target=http%3A%2F%2Fxx%2Fxx%2Fhome.php%23product
my POST response raw:
HTTP/1.1 200 OK
Date: Tue, 10 Sep 2013 09:35:19 GMT
Server: Apache/2.4.4 (Win32) OpenSSL/0.9.8y PHP/5.4.16
X-Powered-By: PHP/5.4.16
Content-Length: 57
Content-Type: text/htmlhttp ://xxx.php#productTest ajax
my GET request raw:
GET xxx.php HTTP/1.1
Host: xxx
Accept: text/html, /; q=0.01
X-Requested-With: XMLHttpRequest
User-Agent: xx
Referer: http ://xxx.php
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8
my GET response raw:
HTTP/1.1 200 OK
Date: Tue, 10 Sep 2013 09:45:43 GMT
Server: Apache/2.4.4 (Win32) OpenSSL/0.9.8y PHP/5.4.16
X-Powered-By: PHP/5.4.16
Content-Length: 152
Content-Type: text/htmlNotice: Undefined index: target in dynamic.php on line 2
Test ajax