dongzouya5792 2013-11-15 08:21
浏览 43
已采纳

AJAX / jquery不适用于返回的PHP站点

my problem is the following: I designed a Webpage using divs. Via Onlick on a link I fill a div with the output of a PHP-File (MySQL-Querys). This PHP-Site is called by a XMLHttpRequest-Function in JavaScript. On the PHP-Site I want to use jQuery to dis-/enable Buttons and Textareas. These jQuery Requests doesn't work. If I call the PHP-Site directly in the Browser everything will work fine. Where's my mistake?

JavaScript to call the PHP-Site and fill the div:

function selected_...(nr)
{
  if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
    xmlhttp=new XMLHttpRequest();
  }
  else
  {// code for IE6, IE5
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
  xmlhttp.onreadystatechange=function()
  {
    if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
      document.getElementById("right_details_content").innerHTML=xmlhttp.responseText;
    }
  }
  xmlhttp.open("GET","/.../ajax_querys.php?id=selected_...&nr="+nr,true);
  xmlhttp.send();
}

Output of PHP-Site:

if($row['anwendung'] == "...") {
            echo "<span>name:</span><input type=\"text\" id=\"name\" name=\"servername\" value=\"" . $row['rechner'] . "\" disabled><br><br>";
            echo "<span>wort:</span><input type=\"text\" id=\"word\" name=\"password\" value=\"" . $word . "\" disabled><br><br>";
            echo "<span>Bemerkung:</span><textarea id=\"right_details_content_textarea\" rows=\"5\" name=\"bemerkung\" disabled>" . $row['bemerkung'] . "</textarea><br><br><br><br><br>";
            echo "<input type=\"hidden\" name=\"nr\" value=\"" . $row['nr'] . "\"><br>";
            echo "<div class=\"left\"><input type=\"button\" id=\"edit\" name=\"edit\" value=\"bearbeiten\"><input type=\"button\" id=\"cancel\" name=\"cancel\" value=\"abbrechen\" style=\"display: none;\"></div>";
            echo "<div class=\"center\"><input type=\"button\" id=\"save\" name=\"save\" value=\"speichern\" disabled></div>";
            echo "<div class=\"right\"><input type=\"button\" id=\"delete\" name=\"delete\" value=\"l&ouml;schen\"></div>";

Ajax-Part:

$(document).ready(function () {
// alert('Fertig');
    $("#edit").click(function(){
// alert('Click');
        if($("#save").attr("disabled")) {
            $("#name").removeAttr("disabled");
            $("#word").removeAttr("disabled");
            $("#right_details_content_textarea").removeAttr("disabled");
            document.getElementById("edit").style.display = "none";
            document.getElementById("cancel").style.display = "inline";
            $("#save").removeAttr("disabled");
        }
    });
});
  • 写回答

1条回答 默认 最新

  • douze2890241475 2013-11-15 08:43
    关注

    what a mass question. well, i think since you are using jquery it is better to use $.ajax to request server.

    something like this:

        $.ajax({
            url: "/.../ajax_querys.php?id=selected_...&nr=",
            type: "GET",
            processData: false,
            contentType: false,
        }).done(function(res){
          console.log(res);
          $("#right_details_content").html(res);
        }).fail(function(err){
           console.log(err);
        });                 
        });
    

    check this, if doesn't work anyway, check request URL and limitation on your code. good luck.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 运动想象脑电信号数据集.vhdr
  • ¥15 三因素重复测量数据R语句编写,不存在交互作用
  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目