duanchun2349 2015-12-29 16:21
浏览 33
已采纳

Jquery调用PHP

I'm attempting to call a PHP file from Jquery. My website shows "hi" once my button is clicked so I know the click() function is being called but I don't get a response from my test.php file. Furthermore, my php file loads without error when called independent from this script.

<html>
<head>
<script language="JavaScript" type="text/javascript" src="jquery-2.1.4.js"></script>
<script type="text/javascript">

$(document).ready(function(){
    $('#submitButton').click(function(){
    //var theName = $( "#name" ).val();
    //var theID = $( "#transaction" ).val();
    alert("hi");
           $.ajax({
              url: "test.php?name=Charlie&transID=1234",
              type:'get',
              success: function(data){
                  alert(data);
              }
           });
        }
    )
});
</script>

</head>
<body>
    <form action="" method="POST">
    <input id="name" type="text" size="20" placeholder="Enter Your Name">
    <input id="transaction" type="hidden" name="transactionID" value="12345">
    <input id="submitButton" type="submit" name="submit" value="Call PHP">
    </form>
</body>

</html>

PHP:

<?php
$name=$_GET['name'];
$id=$_GET['transID'];

echo("Thank you $name for transaction #:$id");
?>

Thanks,
Craig

  • 写回答

2条回答 默认 最新

  • doucao1066 2015-12-30 11:29
    关注

    The solution was to turn off my password protected directory on my webserver which hosted these files in order to successfully call the php file using jquery. With the password protected directory turned on the jquery threw a Error 401 which I was able to catch by viewing the Network tab within Chrome. Still unsure why I was able to provide username/password once and continually access the files via my browser while my script was denied access during the same session.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

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