douhuangjie4503 2014-10-23 04:05
浏览 110
已采纳

使用ajax调用php函数

I have a editor embeded in the html page

<div id="editor">
Problem Statement goes here&hellip;
</div>

I basically want to store the contents written in editor to a file(preferably in rich text format). I used a script (given below) for storing the contents in a string.(This I used by referring to HTML div text to save and display )

<script type='text/javascript' src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"> 
     var StoreEditorContent;  //declare a variable to save Content

      document.getElementById('save').addEventListener("click", SaveText);  // adding event listner for onclick for Saving text

    function SaveText(){

       StoreEditorContent = document.getElementById('editor').innerHTML; // Save the Content into 
       document.getElementById('editor').innerHTML = ""; // to blank the editor Content
       window.onload = function(){

                $.ajax({
                    url: "submit_request.php",
                    type: "GET",
                    success: function writeMsg(StoreEditorContent){
                       //Not sure if this part is right.
                    }
                });   
        }
    }

    </script>

This of course is storing in the contents in a string StoreEditorContent. I now want to pass this string to a php function which will write this(StoreEditorContent) to a file.The php file that contains function to write is given below

<?php

function writeMsg($msg){
    $file = "myfile.txt";
    file_put_contents($file, $msg);
}
?>

I know I need to use ajax here, but cannot figure out how? Any help appreciated.

  • 写回答

1条回答 默认 最新

      报告相同问题?

      相关推荐 更多相似问题

      悬赏问题

      • ¥15 mysql 视图里面如何写时间排序
      • ¥20 misc尽快完成,急! ! !
      • ¥15 protel99.SE提示一下弹窗
      • ¥15 银河麒麟v10 执行.run失败如何解决
      • ¥15 如何用Python打开LA文件
      • ¥15 用mysql做一个高校工资管理系统
      • ¥21 Multisim设计用三端集成稳压器设计稳压电路
      • ¥15 tp6,在iframe里的网址通过获取url参数失败
      • ¥15 打开opendaylight查看拓扑,为什么直接就显示了两个Switch,在mininet配置了一个topo,这两个Switch还在
      • ¥15 无法远程连接pgsql