dongtaogou6226 2016-07-17 12:27
浏览 22
已采纳

来自Ajax调用的回声结果

How can one have the results of an echo display back on the page index.php where the script executes the action.php

Example index.php calls action.php (AJAX) once all is successful action.php will echo some text . Then index.php has this displayed

window.alert(data);
$('#data').val('Sent');

A the moment I have it in a window.alert but I would like no alert just text appear on the index.php from the echo action.php

 <script>
// initiate the document for data
 $(document).ready (
   function()
   {
// I declare here id of object and action event
$('#msg').on('click', function() {

//to disable button after click
// code here for disable button


var info = $('#name').val();
$.ajax({
method: "POST",
url: "actions/action_comment.php",
//pass my variables to ajax - jq here in data name:
data: {

//id is id of the profile you are viewing eg , who the comment is for
name: info, recptid: '<?php echo $_GET["id"]; ?>'  , 

//que is the username of the profile you are viewing (not you) eg name of person comment is for
name: info, q: '<?php echo $userrecivmsg; ?>' , 

// myid is the id OF YOU  eg id of person sending the comment
name: info, myid: '<?php echo $myid; ?>' , 

// me is the username of YOU eg name of person sending the comment
name: info, me: '<?php echo $usersendingmsg; ?>'
},

         //feed the success my data to return results
    success: function(data){

            $('#data').append(status);

              //ON THIS LINE I WOULD LIKE TO HAVE TEXT DISPLAYED ONLY NOT AS AN ALERT OR DIALOG BOX
               window.alert(data);
               $('#data').val('Sent');

    } // end 
    }); // end

       // STOP DEFAULT BEHAVIOR
      return false;

   }); // end
   }); // end
        </script>

Thanks and Thanks again

  • 写回答

1条回答 默认 最新

  • dougu9895 2016-07-17 12:30
    关注

    Add an element in your index.php where you want to display the result

    example <div id="showResult"></div>

    Then in your success function in ajax

    $("#showResult").text(data);

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

报告相同问题?

悬赏问题

  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?