dpowt82802 2016-12-23 11:02
浏览 31

JavaScript不发送给PHP

I have a form with three inputs and a php file with a function conv() with takes three paramater. I want when a user type in a textfeild( this text filed has onlick function called post()) the form data should be posted to php and results from php to be displayed in a filed with ID results. I have my code but its not working. Can any one help.

             <script>
function post(){
         var hr = new XMLhttpRequest();
        var url = "curencyconvert.php";
        var param = document.getElementsById("param").value;
        var param2 = document.getElementsById("param2").value;
        var param3 = document.getElementsById("param3").value;
        var vals = "param="+param+"&param2="+param2+"& param3"+param3;
        hr.open("POST",url,true);
        hr.sendRequestHeader("Content-type","application/x-www-form-urlencoded");
        hr.onreadystatechange= function(){
                if(hr.readyState==4 && hr.status==200){
                    var return_data = hr.responseText;
                    document.getElementById("results").innerHTML = return_data;
                    }

        }
    hr.send(vals);
    }
</script>

And my PHP file is this:

              function Conv($param,$param2,$param3){
                 $restults= $_POST['param'];
                  return $restults;

            }
  • 写回答

2条回答 默认 最新

  • douxuan4556 2016-12-23 11:18
    关注

    Where are you calling the post function written in Javascript and function in PHP should echo instead of return and also ...

    if(isset($_POST)){
    //Calling the defined function here
    Conv($_POST['param'], $_POST['param2'], $_POST['param3']);
    }
    

    should be added to the php file

    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度