doujingjiao0015 2016-06-10 13:15 采纳率: 0%
浏览 24

如何将数据发送到另一个页面,而无需激发当前页面的PHP

so I am having a page where there is an input field. I want this to work like a CMS system. Let's say that there are options. What I am working on now is one where you can specify how long the summery will be for the content. So I want the input to be saved and sent to the function file where I can use that information in a function. I don't want to be sent to this function file site. Similar to how you can save options in wordpress, but you stay on the same page. I imagine that I perhaps have to use AJAX.

Any help on how I can do this?

  • 写回答

1条回答 默认 最新

  • douduoyan5943 2016-06-10 13:33
    关注

    If you would like to use some JavaScript here, then localStorage could be of great help to you.

    Suppose you have following html form:

    <input id = "foo" type = "text">
    

    Write this JavaScript to store the value:

    var val = foo.value;
    localStorage.setItem(formV,val);
    

    And the following to retireve it:

    val = localStorage.getItem(formV);
    

    You can then make an AJAX request to transfer the data to a PHP file:

    request = $.ajax({
            type: 'POST',
            url: 'form.php',
            data: { text1: val}});
    
            request.done( function(response) {
    
        alert("cool!");
            })
    

    On form.php side:

    $val = $_POST['text1'];
     echo $val;
    

    You can learn more about localStorage here and many other places.

    评论

报告相同问题?

悬赏问题

  • ¥20 数学建模,尽量用matlab回答,论文格式
  • ¥15 昨天挂载了一下u盘,然后拔了
  • ¥30 win from 窗口最大最小化,控件放大缩小,闪烁问题
  • ¥20 易康econgnition精度验证
  • ¥15 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能