dpsx99068 2015-11-09 14:15
浏览 49

使用ajax从html文件执行php代码

I am new to php development and I am stuck on something stupid : I want to execute a php script from my html page.

I do the following to do so :

    $.ajax({
        type: "GET", 
        url: "test1.php",
        success: function(response) {
            //alert(response);
            console.log(response);
        },

        error: function(response) {

        }
    });

But when I log the response, I see the php source code in the response :

[Log] <?php  (localhost, line 23)
  $output = "LALALALALALALALALALALALALA"
  echo $output;
?> 
  • 写回答

1条回答 默认 最新

  • duanchi1230 2015-11-09 14:30
    关注

    Try this ... call in head tag

    <head>
     <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
     <script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.18/jquery-ui.min.js" type="text/javascript"></script>
    </head>  
    

    in javascript tag

    $.ajax({
                    type: "GET",
                    url: "test1.php",
                    success: function (html) {
    console.log(response);
                    },
    
            error: function(response) {
    
            }
                });
            return false;
    
    评论

报告相同问题?

悬赏问题

  • ¥15 高德地图点聚合中Marker的位置无法实时更新
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办