duanpo7282 2016-07-28 19:46
浏览 21

为什么我的PHP / get请求在jquery上显示弹出的所有php代码?

The following is my jquery/javascript code in my javascript file:

function userInput(){
        var name = form1.elements["name"].value;
        names1.push(name);
        console.log(names1);
        for(m=0; m<names.length; m++){
            console.log(names[m]);
            console.log(names1[0]);
            if (names[m] == names1[0]){
                    flag = "no";
                    m = names.length;
            }
            else{
                    flag = "yes";
            }
            console.log(names[m]);
            console.log(names1[0]);

    }
    $.ajax({
      url:"test.php", //the page containing php script
      type: "get", //request type
      success:function(result){
        alert(result);
                    console.log("post worked! :D");
    }
    });
    //run python training script here! send over names parameter

};

The following is test.php:

<?php
   echo("Hello World");
 ?>

In my html, I call UserInput() in a form so that when a button is clicked, this function runs. This part is working as expected. The issue that is occurring is that the Javascript runs the "test.php" code, however, when this is called, the website displays a pop up with all of the php code listed. I'm unsure of why this is occurring...I don't think it's because of the php code because I've tried multiple lines of PHP code that did not include echo and such..let me know if you need me to include any more information!

  • 写回答

1条回答 默认 最新

  • drcj64241 2016-07-28 20:14
    关注

    PHP is a server language. If you haven't used them before, you probably aren't using a server, local or external. Check out here on how to set it up: http://www.w3schools.com/php/php_install.asp Once it is setup, load all your code onto the server (which really just means you moving your code to a certain directory) and then try running it.

    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog