简体   繁体   English

进行更改后刷新div内容

[英]Refresh div contents after making changes

Below is my code which is working fine... 下面是我的代码,可以正常工作...

<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 php code... 和php代码...

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>');

As you can see, I am using AJAX to fetch data from server and displayed within its working fine but I need to refresh div everytime I make changes . 如您所见,我正在使用AJAX从服务器获取数据并在其正常工作下显示,但每次进行更改时,我都需要刷新div。

How to refresh div when I make some changes... also I need to add a symbol or loading image, when the data is being from server.....How to do that? 进行某些更改时如何刷新div ...当数据来自服务器时,我还需要添加符号或加载图像.....该怎么做?

Maybe try this: 也许试试这个:

Javascript Java脚本

<script type="text/javascript">
$(document).ready(function(){

  $('#theIMform input')
    .change(function(){
      // Automatically creates a Query String for all fields within the parent form
      formdata = $(this).closest('form').serialize();

      $.ajax({
        type : "POST" ,
        url : "i.php" ,
        data : formdata ,              
        cache : false ,
        error : function( jqXHR , textStatus , errorThrown ){
          // Something went wrong
        } ,
        success : function( data , textStatus , jqXHR ){
          $( "#div_im" )
            .hide()
            .html( '<img src="'+data+'">' )
            .show();

        }
      });
    });

});
</script>

PHP 的PHP

?>
<form id="theIMform" name="theIMform">
  Name: <input type="text" id="Name" value="your name"  name="Name" />
  pointsize: <input type="text" id="pointsize" value="50" name="pointsize" />
  format: <input type="text" id="format" value=".gif" name="format" />
  BackGround Color: <input type="text" id="bckclr" value="red" name="bckclr" />
  FontColor: <input type="text" id="color" value="white" name="color" />
  Border Color: <input type="text" id="bcolor" value="blue" name="bcolor" />
  <a href="./lang/ims.php"><img src="<?php echo $image; ?>" height="82" width="82" /></a>
  Font: <input type="text" id="font" value="<?php echo $image1; ?>" name="font" />
</form>
<div id="div_im">replace me</div>
<?php

When you change a page element it's refreshed automatically. 更改页面元素时,它会自动刷新。

I think your problem is about this line 我认为您的问题与这条线有关

$("#Div_Im").html(pic).show();

because you call show to the img element and not on the div. 因为您将show称为img元素,而不是div。

try to change it in 尝试改变它

$("#Div_Im").html(pic);
$("#Div_Im").show();

furthermore i suggest you use jquery to get values, so you need to change color=document.getElementById("color").value; 此外,我建议您使用jquery来获取值,因此您需要更改color=document.getElementById("color").value; in a more easy color = $('#color').val(); 用更简单的color = $('#color').val();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM