이 글에서는 가장 간결하고 이해하기 쉬운 Ajax 비새로고침 메시지 시스템인 새로고침하지 않는 뉴스 메시지 시스템을 소개합니다. 소스 코드에서는 필요에 따라 데이터 검증을 받아들이는 과정을 생략할 수 있습니다. . 주제를 살펴보겠습니다.
핵심 소스 코드:
1. 구성 파일: config.php, 코드는 다음과 같습니다.
<?php //数据库配置信息(用户名,密码,数据库名,表前缀等) $cfg_dbhost = "localhost"; $cfg_dbuser = "root"; $cfg_dbpwd = "root"; $cfg_dbname = "ajaxdemo1"; $cfg_dbprefix = ""; $link = mysql_connect($cfg_dbhost,$cfg_dbuser,$cfg_dbpwd); mysql_select_db($cfg_dbname); mysql_query("set names utf8"); ?>
2. 요청 처리: deal.php, 코드는 다음과 같습니다:
<?php header("Content-type:text/html;charset=utf-8"); include "config.php"; //post接收数据,只是演示效果,这里就省去验证了 $name = $_POST['name']; $content = $_POST['content']; $sql = "insert into test (name,content) values ('{$name}','{$content}');"; $res = mysql_query($sql,$link); if($res){ echo '{"name": "'.$name.'","content": "'.$content.'","status": "1"}'; } ?>
3. 홈페이지 코드: index.php, 코드는 다음과 같습니다.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>无刷新</title> <link href="css/css.css" type="text/css" rel="stylesheet" /> <style type="text/css"> body{color:#555;font-size:14px;padding:0;margin:0;} #form { background:#dedede; padding:10px 20px; width:300px;} #show{ background:#f6f6f6;padding:10px 20px; width:300px;} #show p{ margin:6px; font-size:13px; line-height:22px; border-bottom:1px dashed #cdcdcd;} </style> <script type="text/javascript" src="jquery-1.7.2.min.js"></script> <script type="text/javascript"> $(function(){ $("#sub").click(function(){ //只是说明原理,然后这里省去了验证文本框内容的步骤,直接发送ajax请求 $.post("deal.php",{name : $("#name").val(), content : $("#content").val()}, function(data){ if(data.status){ var str = "<p><strong>"+data.name+"</strong> 发表了:"+data.content+"</p>"; $("#show").prepend(str); //在前面追加 }else{ alert("评论失败"); } }, 'json'); }); }); </script> </head> <body> <div id="form"> <form action="deal.php" method="get" id="suggest_form"> 用户名:<input type="text" name="name" id="name" /><br/> 内 容:<textarea name="content" id="content"></textarea> <input type="button" value="发布" id="sub" /> </form> </div> <div id="show"> <?php include "config.php"; $sql = "select * from test;"; $res = mysql_query($sql,$link); while($row=mysql_fetch_array($res)){ echo "<p><strong>".$row['name']."</strong> 发表了:".$row['content']."</p>"; } ?> </div> </body> </html>
데이터베이스 파일의 코드는 다음과 같습니다.
DROP TABLE IF EXISTS `test`; CREATE TABLE `test` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `name` varchar(64) NOT NULL, `content` text NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
위 내용은 제가 공유한 새로고침 없이 뉴스 메시지 시스템을 PHP Ajax로 구현한 내용입니다. 모든 분들의 학습에 도움이 되기를 바랍니다.

의존성 (di) inphpenhancescodeflexibility 및 testability는 decouplingdependencycreation fromusage.toimplementDieffectically : 1) addicontainersjudicuelyToavoidover-Engineering.2) indhe. 3) adhe

toimproveyourphpwebsite의 성능, UsetheseStrospations : 1) ubstractOpCodeCachingWithOpCaceToSpeedUpscriptScriptIngretation.2) 최적화 된 AabaseQueriesBysElectingOnlynecessaryFields.3) UsecachingsystemsLikeredSormcedUcedUcedUcedALOW

예, itispossibletosendmassemailswithphp.1) uselibraries -lifephpmailerorswiftmailerforfficialemailsending.2) emubledelaysbetemailstoavoidspamflags.3) personalizeemailsingdynamiccontenttoimproveengement.4) usequeuesystemslikerbitmbitmquredisb

의존성 (di) inphpisadesignpatternthatachievesinversionofcontrol (ioc) by ancelociestobeinjectedintoclasses, 향상 모듈 성, 테스트 가능성 및 flexibility.didecouplesssclassessfromspecificimplementations, codemoremanageableandadapt

PHP를 사용하여 이메일을 보내는 가장 좋은 방법은 다음과 같습니다. 1. 기본 전송에 Php 's Mail () 함수를 사용합니다. 2. phpmailer 라이브러리를 사용하여 더 복잡한 HTML 메일을 보내십시오. 3. Sendgrid와 같은 트랜잭션 메일 서비스를 사용하여 신뢰성 및 분석 기능을 향상시킵니다. 이러한 방법을 사용하면 이메일이받은 편지함에 도달 할뿐만 아니라 수신자를 유치 할 수 있습니다.

PHP 다차원 어레이에서 총 요소 수를 계산하는 것은 재귀 적 또는 반복적 인 방법을 사용하여 수행 할 수 있습니다. 1. 재귀 방법은 배열을 가로 지르고 중첩 배열을 재귀 적으로 처리함으로써 계산됩니다. 2. 반복 방법은 스택을 사용하여 깊이 문제를 피하기 위해 재귀를 시뮬레이션합니다. 3. Array_Walk_Recursive 함수도 구현할 수 있지만 수동 계산이 필요합니다.

PHP에서, do-while 루프의 특성은 루프 본체가 적어도 한 번 실행되도록하고 조건에 따라 루프를 계속할지 여부를 결정하는 것입니다. 1) 조건부 점검 전에 루프 본체를 실행하며, 사용자 입력 확인 및 메뉴 시스템과 같이 작업을 적어도 한 번 수행 해야하는 시나리오에 적합합니다. 2) 그러나, do-while 루프의 구문은 초보자들 사이에서 혼란을 야기 할 수 있으며 불필요한 성능 오버 헤드를 추가 할 수 있습니다.

PHP의 효율적인 해싱 스트링은 다음 방법을 사용할 수 있습니다. 1. 빠른 해싱에 MD5 기능을 사용하지만 비밀번호 저장에는 적합하지 않습니다. 2. SHA256 기능을 사용하여 보안을 향상시킵니다. 3. Password_hash 함수를 사용하여 비밀번호를 처리하여 최고 보안과 편의성을 제공하십시오.


핫 AI 도구

Undresser.AI Undress
사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover
사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool
무료로 이미지를 벗다

Clothoff.io
AI 옷 제거제

Video Face Swap
완전히 무료인 AI 얼굴 교환 도구를 사용하여 모든 비디오의 얼굴을 쉽게 바꾸세요!

인기 기사

뜨거운 도구

Eclipse용 SAP NetWeaver 서버 어댑터
Eclipse를 SAP NetWeaver 애플리케이션 서버와 통합합니다.

PhpStorm 맥 버전
최신(2018.2.1) 전문 PHP 통합 개발 도구

VSCode Windows 64비트 다운로드
Microsoft에서 출시한 강력한 무료 IDE 편집기

스튜디오 13.0.1 보내기
강력한 PHP 통합 개발 환경

드림위버 CS6
시각적 웹 개발 도구