I ve been trying to get this really simple example of using AJAX with JQuery and PHP to work with no luck (here s the page for the sample). I ve had a look at quite a few posts with similar discriptions and none have helped...
我完全照搬了这部法典,但我本应成功履行的职能从未被人要求。 作为一次试验,在请购美元时,我对数据部分(isendValue:str})和JSON部分进行了评论,并对成功功能的体发出警报,看看它是否被叫来,是否是。 因此,我猜测那里的情况与我如何制作我的数据有什么错误? 我还试图在警示中显示从AJAX号呼吁中恢复的数据,数据是未申报的(数据)。
This is a copy of my code, you can see the full example via the link above and also a working example from the author of the tutorial here: http://www.devirtuoso.com/Examples/jQuery-Ajax/
JQuery:
$(document).ready(function(){
$( #txtValue ).keyup(function(){
sendValue($(this).val());
});
});
function sendValue(str){
$.post("ajax.php",
{ sendValue: str },
function(data){
$( #display ).html(data.returnValue);
},
"json"
);
}
PHP:
<?php
//Get Post Variables. The name is the same as
//what was in the object that was sent in the jQuery
if (isset($_POST[ sendValue ])){
$value = $_POST[ sendValue ];
}else{
$value = "";
}
//Because we want to use json, we have to place things in an array and encode it for json.
//This will give us a nice javascript object on the front side.
echo json_encode(array("returnValue"=>"This is returned from PHP : ".$value));
?>
传真:
<body>
<p>On keyup this text box sends a request to PHP and a value is returned.</p>
<label for="txtValue">Enter a value : </label><input type="text" name="txtValue" value="" id="txtValue">
<div id="display"></div>
</body>
感谢!
EDIT: I rewrote my $.post into a $.ajax with an error function in it. I m definitely hitting the error function and the error is a parse error - I m guessing it s coming from my PHP script when I call json_encode... here s a screenshot from firebug - anyone got any more ideas?:
http://postimage.org/image/5h4un2q9z/ rel=“nofollow noreferer”>Screenshot 1 - firebug console
Screenshot 2 - firebugwatchwell
www.un.org/Depts/DGACM/index_spanish.htm 感谢迄今为止所提供的一切帮助,确实赞赏这一帮助。