English 中文(简体)
J Query /PHP calls with AJAX not working
原标题:JQuery / PHP call with AJAX not working

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

screen grab of firefox console screen grab of watch on error function

www.un.org/Depts/DGACM/index_spanish.htm 感谢迄今为止所提供的一切帮助,确实赞赏这一帮助。

最佳回答

我注意到,var str =美元(#txt ).val()将给你一个错误,因为$(#txt )不存在,应当成为$(#txtValue )

在审视你的法典之后,我下一步将尝试利用一些专人来推翻你的法典。 debug() in Java, 并在PHP中反映一些内容。 我建议,如果将EE升级到E9,并使用其开发工具,那么你会获得 Chrome/Firefox。 利用上述工具,将使你更好地了解贵国法律是如何实施的。

我的第一步是确保关键在于:

 $(document).ready(function(){
        $( #txtValue ).keyup(function(){
            alert( keyUp );
            sendValue($(this).val());
        });
 });

第二步是确保派遣人员 价值为:

function sendValue() {
    alert( sendValue );
    var str = $( #txt ).val();
    tmr = null;


    $.post(
         test.php , 
        { sendValue: str }, 
        function(data) { 
            alert( inside post );
            $( #output ).html(data.returnValue); 
        }, 
         json 
    );
}
问题回答

我看不出你的各种因素正在产生多少成果,但我不认为我可以告诉你什么是固定的,但这个例子与你相似(尽管它拥有一个全方位的购买力平价档案,而不是像你这样两个)。 我也增加了350个短时间,使用户能够在没有网页要求每个关键中点的情况下进行分类。 一旦暂停使用,数据便可打碎。

资料来源:test.php

<?php

if(isset($_POST[ sendValue ]))
{
    echo json_encode(
        array( returnValue  => 
               Returned:   . $_POST[ sendValue ]));
    exit();
}

?>
<!DOCTYPE html 
    PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>AJAX Sample</title>
</head>
<body>

<input type="text" id="txt" />
<div id="output"></div>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js" 
    type="text/javascript"></script>
<script type="text/javascript">

var tmr = null;

$(function () {
    $( #txt ).keyup(function() {
        if(tmr != null)
            clearTimeout(tmr);
        tmr = setTimeout("sendValue()", 350);
    });
});

function sendValue() {
    var str = $( #txt ).val();
    tmr = null;

    $.post(
         test.php , 
        { sendValue: str }, 
        function(data) { 
            $( #output ).html(data.returnValue); 
        }, 
         json 
    );
}
</script>
</body>
</html>

www.un.org/Depts/DGACM/index_spanish.htm 任何人在座寻求回答类似问题:

我尝试了几件事来说明正在做的事情,贬低了电文等,所有东西都看得很美。 然后,我把我的代码放在一个虚拟箱子上,运行一个灯塔,并安装在我的网络服务器上,看看它是否属于环境。 我的代码在我的网络服务器和虚拟箱上工作。 我然后认识到,我有两套双管齐下安装在我的开发系统上。 我不敢肯定为什么会造成这一问题,但把这些问题推回并重新纳入到发展中国家体系中。

审判

$(document).ready(function(){ 
    $( #txtValue ).keyup(function(){ 
        $.post("ajax.php",{ sendValue: str },   function(data){ 
        $( #display ).html(data.returnValue); 
    }, 
    "json" 
    ); 
}); 
});




相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

image changed but appears the same in browser

I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签