Я пытаюсь вернуть значения из $.post
, и ничего не получаю.Вот фрагменты кода:
<!-- language: lang-js -->
$(document).ready(function(){
$('.d1').dblclick(function() {
$(this).css("background-color","blue");
var datas = $(this).attr('id');
$.post(
"simpleData.php",
{"chess":datas},
{dataType: "JSON"},
{async:false},
{contentType: "application/json; charset=utf-8"},
{success: function(msg){
alert(msg.d);
var resultAsString = msg.d;
document.write(resultAsString);
}
});
});
});
Вот разделение для вывода.Я не получаю вывод здесь:
<!-- language: lang-php -->
<div id = "output">
<?php
echo "This is the default output <br />";
echo $_REQUEST['chess'];
?>
<?php
print_r($_REQUEST);
?>
Вот вызываемая программа php (simpleData.php
):
<!-- language: lang-php -->
<html>
<body
<?php
$move_from = $_REQUEST['chess'];
var_dump($_REQUEST);
echo "this is move_from $move_from";
?>
</body>
</html>
Я получаю правильный выводиз этого, но это никогда не появляется в div.Кроме того, я не получаю вывод из оповещения.
Помогите и посоветуйте, пожалуйста.
Вот обновленный код , который, к сожалению, все еще не работает.Результат появляется в DIV, но все, что он говорит, это «неопределенный».Кроме того, шахматная доска, которая находится на странице, уничтожена.
<script type="text/javascript">
$.ajaxSetup ({
cache: false
});
$(document).ready(function(){
$('.d1').dblclick(function() {
$(this).css("background-color","blue");
var datas = $(this).attr('id');
$.post("simpleData.php", {
data: {"chess":datas},
dataType: "json",
async:false,
contentType: "application/json; charset=utf-8",
header: "HTTP/1.1 200 OK",
success: function(html){
var resultAsString = html;
$("#output").html(resultAsString);
document.write(resultAsString);
}
});
</script>
Вот программа [simpleData.php], которая называется:
<html>
<body
<?php
$move_from = $_REQUEST['chess'];
var_dump($_REQUEST);
echo "this is move_from $move_from";
?>
</body>
</html>
Вот вывод html изFirebug:
Notice: Undefined index: chess in /var/www/simpleData.php on line 12 array(6) { ["data"]=> array(1) { ["chess"]=> string(2) "e8" } ["dataType"]=> string(4) "json" ["async"]=> string(5) "false" ["contentType"]=> string(31) "application/json; charset=utf-8" ["header"]=> string(15) "HTTP/1.1 200 OK" ["success"]=> string(9) "undefined" } this is move_from
Помощь и совет, пожалуйста.Спасибо
Это самый последний код:
<script type="text/javascript">
$.ajaxSetup ({
cache: false
});
$(document).ready(function(){
$('.d1').dblclick(function() {
$(this).css("background-color","blue");
var datas = $(this).attr('id');
$.post("simpleData.php", {
data: {"chess":datas},
dataType: "json",
async:false,
contentType: "application/json; charset=utf-8",
header: "HTTP/1.1 200 OK",
success: function(html){
newProcessData(html);
}
});
});
});
function newProcessData(html){
var resultAsString = html;
$("#output").html(resultAsString);
document.write(resultAsString);
alert("yippee");
}
Вот программа, которая называется (simpleData.php) [она имеет не изменено]
<html>
<body>
<?php
$move_from = $_REQUEST['chess'];
var_dump($_REQUEST);
echo "this is move_from $move_from";
?>
</body>
</html>
Я знаю, что код достиг функции newProcessData, поскольку отображается предупреждение.
Вот вывод из Firebug:
Заголовки:
Date Mon, 22 Aug 2011 04:01:42 GMT
Server Apache/2.2.19 (Debian)
X-Powered-By PHP/5.3.7-1
Vary Accept-Encoding
Content-Encoding gzip
Content-Length 401
Keep-Alive timeout=15, max=99
Connection Keep-Alive
Content-Type text/html
Request Headersview source
Host localhost
User-Agent Mozilla/5.0 (X11; Linux i686; rv:6.0) Gecko/20100101 Firefox/6.0 Iceweasel/6.0
Accept */*
Accept-Language en-us,en;q=0.5
Accept-Encoding gzip, deflate
Accept-Charset ISO-8859-1,utf-8;q=0.7,*;q=0.7
Connection keep-alive
Content-Type application/x-www-form-urlencoded; charset=UTF-8
X-Requested-With XMLHttpRequest
Referer http://localhost/jq3_test.php
Content-Length 137
Pragma no-cache
Cache-Control no-cache
POST:
async false
contentType application/json; charset=utf-8
dataType json
data[chess] e8
header HTTP/1.1 200 OK
success undefined
Source
data%5Bchess%5D=e8&dataType=json&async=false&contentType=application%2Fjson%3B+charset%3Dutf-8&header=HTTP%2F1.1+200+OK&success=undefined
HTML:
Notice: Undefined index: datas in /var/www/simpleData.php on line 13 array(6) { ["data"]=> array(1) { ["chess"]=> string(2) "e8" } ["dataType"]=> string(4) "json" ["async"]=> string(5) "false" ["contentType"]=> string(31) "application/json; charset=utf-8" ["header"]=> string(15) "HTTP/1.1 200 OK" ["success"]=> string(9) "undefined" } this is move_from
Любая помощь, которая может быть оказана, будет высоко оценена Спасибо