duanshaiduhao2471 2014-12-12 16:57
浏览 40

将值发布到没有重定向的php文件

Guys i have a problmm and i want your help.Actually i want to POST a value to php file without redirect me to this file... My form:

<form method="post" role="form" action="">
    <div class="form-group">
      <label>Change threshold:</label>
      <input name="thr"  class="form-control" id="thr" placeholder="Enter Threshold">
    </div>
    <button type="submit" class="btn btn-default" name="thre" >Change</button>
</form>

I tried a curl post call but it didn't work. My call:

if (isset($_POST['thre'])) {
            $value=$_POST['thr'];
            $json_string='{"thr":"'.$value.'"}';
            $url = 'http://147.27.50.55/IDM/subsc.php';
            $curl = curl_init( $url );
            curl_setopt($curl,CURLOPT_URL, $url);
            curl_setopt($curl, CURLOPT_POST, true);
            curl_setopt($curl, CURLOPT_POSTFIELDS, $json_string);
            curl_setopt($curl3, CURLOPT_HTTPHEADER, array(                                                                          
            'Content-Type: application/json',                                                                        
            'Content-Length: ' . strlen($json_string))                                                                         
            );  
            $result=curl_exec($curl);
            curl_close($curl); 
         }

Finally i want get teh value like this:

$v=$_GET['$value'];

Where is the problem?

  • 写回答

1条回答 默认 最新

  • dpt1712 2014-12-12 17:09
    关注

    You need to tell the client (usually the browser) that you just want some data, not a whole new site. There is nothing the server or the PHP script can do to modify this behavior. A cURL call from your PHP script just starts another request, it will not replace the original request that your browser send to the server.

    Usually this is done via javascript in the form of an XMLHttpRequest. The technique is called AJAX, all modern javascript frameworks (like jQuery) have ready made functions to handle it

    评论

报告相同问题?

悬赏问题

  • ¥15 我的代码无法在vc++中运行呀,错误很多
  • ¥50 求一个win系统下运行的可自动抓取arm64架构deb安装包和其依赖包的软件。
  • ¥60 fail to initialize keyboard hotkeys through kernel.0000000000
  • ¥30 ppOCRLabel导出识别结果失败
  • ¥15 Centos7 / PETGEM
  • ¥15 csmar数据进行spss描述性统计分析
  • ¥15 各位请问平行检验趋势图这样要怎么调整?说标准差差异太大了
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
  • ¥15 wpf界面一直接收PLC给过来的信号,导致UI界面操作起来会卡顿
  • ¥15 init i2c:2 freq:100000[MAIXPY]: find ov2640[MAIXPY]: find ov sensor是main文件哪里有问题吗