基本的 PHP 和 AJAX [英] Basic PHP and AJAX

查看:25
本文介绍了基本的 PHP 和 AJAX的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个大型 PHP 系统,我正在将其更改为 OOP,并希望使用 AJAX 为登录用户更新网页.我完全自学,擅长 HTML、CSS 和 PHP,对 Javascript 有基本的了解.

We have a large PHP system that I am changing to OOP and want to use AJAX to update the web pages for logged in users. I am completely self taught and good on HTML, CSS and PHP with a basic Javascript understanding.

尝试用 PHP 学习 AJAX 正在打败我.在尝试了一组自制的脚本来测试 AJAX 之后,它不起作用,然后我去 Internet 查找示例,但无法使用任何脚本.这是在我的开发 Mac 上运行 MAMP 并使用我们保留当前系统的主机.

Trying to learn AJAX with PHP is defeating me. After trying a self made set of scripts to test AJAX which wouldn't work I then went to the Internet for examples and can't get any to work. This is on my development Mac running MAMP and using my host where we keep the current system.

我的问题是,有没有人有一套简单的hello world"HTML 和 PHP 脚本,他们知道它们可以工作,我可以尝试确认我可以运行已知的东西.

My question is, does anybody have a simple 'hello world' set of HTML and PHP scripts that they know work which I could try to confirm that I can run something known.

非常感谢科林

推荐答案

如果您打算使用 AJAX,我建议您也使用 jQuery.这大大简化了流程,经过了跨浏览器测试,并具有许多易于使用的包装函数.

If you are going to use AJAX I would recommend using jQuery as well. This greatly simplifies the process, is tested cross-browser and has many easy to use wrapper functions.

它真的就像创建一个名为 hello.php

Its really as easy as creating a PHP page called hello.php

<?php
  echo "Hello World";
?>

然后在您的主页面中,您需要获取 jQuery 库并将其连接到文档就绪事件.

Then in your main page you will need to grab the jQuery library and hook it up to the document ready event.

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
<script type="text/javascript">
     $(function(){
       $.get("hello.php", function(data){
           alert(data);
       });
    });
</script>

这实质上是我所知道的最简单的 AJAX hello world 教程:)

This in essence is the simplest AJAX hello world tutorial I know :)

这篇关于基本的 PHP 和 AJAX的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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