drvfqr5609 2012-09-21 10:37
浏览 21
已采纳

为什么我的AJAX代码只能部分工作?

Hello people here is my code

echo('Name: <input type="text" id="Name" onchange="im()" value="your name"  name="Name" />');
echo('pointsize: <input type="text" id="pointsize" onchange="im()" value="50" name="pointsize" />');
echo('format: <input type="text" id="format" value=".gif" onchange="im()" name="format" />');
echo('BackGround Color: <input type="text" id="bckclr" value="red" onchange="im()" name="bckclr" />');
echo('FontColor: <input type="text" id="color" value="white" onchange="im()" name="color" />');
echo('Border Color: <input type="text" id="bcolor" value="blue" onchange="im()" name="bcolor" />');
echo('<a href="./lang/ims.php"><img src="'.$image.'" height="82" width="82" /></a>');
echo('Font: <input type="text" id="font" value="'.$image1.'" onchange="im()" name="font" />');

echo ('<div id="Div_Im">');
echo('replace me');
echo ('</div>');

Here is my AJAX code.

<Script type="text/javascript">
    function im()
    {
        var Name=document.getElementById("Name").value;
        var pointsize=document.getElementById("pointsize").value;
        var format=document.getElementById("format").value;
        var bckclr=document.getElementById("bckclr").value;
        var color=document.getElementById("color").value;
        var bcolor=document.getElementById("bcolor").value;
        var font=document.getElementById("font").value;
        $(document).ready(function(){
            var url='Name='+Name+'&pointsize='+pointsize+'&format='+format+'&bckclr='+bckclr+'&color='+color+'&bcolor='+bcolor+'&font='+font;
            alert(url);
            //-----Sending request to server for getting job name list by ajax-----
            $.ajax({
                type    : "POST",
                url : "i.php?",
                data    : url,              
                cache   : false,
                success : function(html)
                {
                    //document.getElementById('Div_PJobId').style.display="block";
                    //alert('hi');
                    alert(html);
                    var pic='<img src="'+html+'">';
                    $("#Div_Im").html(pic).show();
                }
            });
        });
     }
</script>

And here is my server page code for i.php

$Name=$_POST["Name"];
$pointsize=$_POST["pointsize"];
$bckclr=$_POST["bckclr"];
$color=$_POST["color"];
$bcolor=$_POST["bcolor"];
$format=$_POST["format"];
//$filename = "./lang/sri".$format;
$filename = "./lang/".$Name.$format;
$font=$_POST["font"]; 

$cmd = " -background $bckclr -pointsize $pointsize -font $font -fill $color ".
            " -strokewidth 1 -stroke $bcolor label:\"$Name\" ";

exec("convert $cmd $filename");
//if($filename)
//{}
//echo('<img src="'.$filename.'">');
echo $filename;

Please check the demo link. Contents(image shown in ) of is replacing only if I make changes to name ,but it does not work for color,bcolor,font,...I need to refresh the page every time when I make changes.... is there a way to fix this problem?

  • 写回答

2条回答 默认 最新

  • dongpang9573 2012-09-21 10:54
    关注

    I was debugging your code and found that every thing is working fine on client side as on every change(in input ) you are calling to your server with latest data and replacing your image based on html you get from server.

    I believe there is problem to your server side code. as I saw you are assigning name to created image file using name field value. it means name image file already created for color change as name is already provided. you should look your server side code. some time response is taking infinite time to return from server.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 数据库获取信息反馈出错,直接查询了ref字段并且还使用了User文档的_id而不是自己的
  • ¥15 将安全信息用到以下对象时发生以下错误:c:dumpstack.log.tmp 另一个程序正在使用此文件,因此无法访问
  • ¥15 速度位置规划实现精确定位的问题
  • ¥15 代码问题:df = pd.read_excel('c:\User\18343\Desktop\wpsdata.xlxs')路径读不到
  • ¥15 为什么视频算法现在全是动作识别?
  • ¥15 编写一段matlab代码
  • ¥15 用Python做岩石类别鉴定软件
  • ¥15 关于调取、提交更新数据库记录的问题
  • ¥15 之前删了盘从下vs2022遇见这个问题 搞了一整天了
  • ¥15 从Freecad中宏下载的DesignSPHysics,出现如下问题是什么原因导致的(语言-python)