使用ajax从JS调用PHP函数 [英] calling PHP function from JS with ajax

查看:95
本文介绍了使用ajax从JS调用PHP函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我正在使用javascript编写游戏并使用一些PHP登录注册等。我想链接到外部文件并在那里执行代码,然后在javascript文件中获得结果。我做了一些研究,大多数人都说使用ajax。我对ajax没有经验,所以如果你能提供帮助就会很棒。

这是我的代码:



Hi everybody, I am programming a game with javascript and using some PHP for login register etc.. I want to link to an external file and execute the code there and then get the result in the javascript file. I did some research and most people say to use ajax. I have zero experience with ajax so it would be great if you could help out.
Here is my code:

<html>
    <head>
        <title>
            test
        </title>
    </head>

    <body>
        <script src="http://code.jquery.com/jquery-latest.min.js"></script>
        <script type="text/javascript">
            var timeAtEnd = 1;
            function submitHS () {
            alert("ha");
                $.ajax({
                    $.alert("buahah");
                    type: "GET",
                    url: "mathMemory/submitHS.php",
                    data: {timeAtEnd = "timeAtEnd"}
                    success: function() {
                        echo "success";
                    };
            });
        }
        window.onload = submitHS();
        </script>
    </body>
</html>







我现在真正想做的就是让连接正常工作我不认为这样做。

提前感谢您的帮助!




All I really want to do right now is have the connection work which i don't think it is doing.
Thanks in advance for any help!

推荐答案

.ajax({


.alert(buahah);
类型:GET,
url:mathMemory / submitHS.php,
数据:{timeAtEnd =timeAtEnd }
成功:function(){
echo成功;
};
});
}
window.onload = submitHS();
< / script >
< / body >
< / html >
.alert("buahah"); type: "GET", url: "mathMemory/submitHS.php", data: {timeAtEnd = "timeAtEnd"} success: function() { echo "success"; }; }); } window.onload = submitHS(); </script> </body> </html>







我现在真正想做的就是让连接正常工作我不认为这样做。

提前感谢您的帮助!




All I really want to do right now is have the connection work which i don't think it is doing.
Thanks in advance for any help!


这篇关于使用ajax从JS调用PHP函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆