HTML中的内容
............
">
">
............
<script> <br /> function submit(i) <br /> { <br /> var sendData=""; <br /> if(i=="1"){sendData='{"action":"'+i+'","pw":'+getElementByName+',"email":'+getElementByName+':}';} <br /> $.ajax({ <br /> timeout:5000, <br /> type:"POST", <br /> url:"edit_server.php", <br /> data:sendData, <br /> success:function(data) <br /> { <br /> getData(1); //这是一个函数,用来打开一个页面。 <br /> } <br /> }); <br /> } <br /> </script>
edit_server.php中的内容:
require_once "functions.php";
connectDb();
if($_GET['action']=="1")
{
$pw = $_POST['pw'];
$email = $_POST['email'];
mysql_query("UPDATE basic_information SET pw = '$pw',email = '$email');
if(mysql_errno()){
echo mysql_error();
}else{
getData(1);
}
}
回复讨论(解决方案)
几个问题:
1、edit_server.php 中要检查 $_GET['action']=="1"
但 ajax 的 url 中没有参数(url:"edit_server.php",)
要这样 url:"edit_server.php?action=" + i,
2、sendData='{"action":"'+i+'","pw":'+getElementByName+',"email":'+getElementByName+':}'
这样赋值后 sendData 是字符串,不会被 php 解析成 $_POST 数组
要这样
sendData = {pw : document.getElementByName(‘pw').value, email : document.getElementByName('emal'][0].value }
前端ajax 提交时用了post方式 ,后端PHP 用 if( $_GET['action']=="1") { ....} 来验证所以问题就来了。
修改后
<script> <br /> function submit(i) <br /> { <br /> var sendData=""; <br /> if(i=="1"){sendData={pw:getElementByName("pw").value,email:getElementByName("email").value};} <br /> $.ajax({ <br /> timeout:5000, <br /> type:"POST", <br /> url:"edit_server.php?action="+i, <br /> data:sendData, <br /> success:function(data) <br /> { <br /> alert(data); <br /> getData(1); <br /> } <br /> }); <br /> } <br /> </script>
后台:
if($_POST['action']=="1")
{
$pw = $_POST['pw'];
$email = $_POST['email'];
mysql_query("UPDATE basic_information SET pw = '$pw',email = '$email');
if(mysql_errno()){
echo mysql_error();
}else{
getData(1);
}
}
但依然无法运行,控制台提示ReferenceError: getElementByName is not defined
getElementsByName
改完后,数据依然没有传入
换种ajax方式,初始化后,在提交,发送参数,接收返回数据。
非常感谢诸位大神,已成功解决问题。
if(i=="1"){sendData={pw: document.getElementByName("pw").value,email: document.getElementByName("email").value};}

ThesecrettokeepingaPHP-poweredwebsiterunningsmoothlyunderheavyloadinvolvesseveralkeystrategies:1)ImplementopcodecachingwithOPcachetoreducescriptexecutiontime,2)UsedatabasequerycachingwithRedistolessendatabaseload,3)LeverageCDNslikeCloudflareforservin

You should care about DependencyInjection(DI) because it makes your code clearer and easier to maintain. 1) DI makes it more modular by decoupling classes, 2) improves the convenience of testing and code flexibility, 3) Use DI containers to manage complex dependencies, but pay attention to performance impact and circular dependencies, 4) The best practice is to rely on abstract interfaces to achieve loose coupling.

Yes,optimizingaPHPapplicationispossibleandessential.1)ImplementcachingusingAPCutoreducedatabaseload.2)Optimizedatabaseswithindexing,efficientqueries,andconnectionpooling.3)Enhancecodewithbuilt-infunctions,avoidingglobalvariables,andusingopcodecaching

ThekeystrategiestosignificantlyboostPHPapplicationperformanceare:1)UseopcodecachinglikeOPcachetoreduceexecutiontime,2)Optimizedatabaseinteractionswithpreparedstatementsandproperindexing,3)ConfigurewebserverslikeNginxwithPHP-FPMforbetterperformance,4)

APHPDependencyInjectionContainerisatoolthatmanagesclassdependencies,enhancingcodemodularity,testability,andmaintainability.Itactsasacentralhubforcreatingandinjectingdependencies,thusreducingtightcouplingandeasingunittesting.

Select DependencyInjection (DI) for large applications, ServiceLocator is suitable for small projects or prototypes. 1) DI improves the testability and modularity of the code through constructor injection. 2) ServiceLocator obtains services through center registration, which is convenient but may lead to an increase in code coupling.

PHPapplicationscanbeoptimizedforspeedandefficiencyby:1)enablingopcacheinphp.ini,2)usingpreparedstatementswithPDOfordatabasequeries,3)replacingloopswitharray_filterandarray_mapfordataprocessing,4)configuringNginxasareverseproxy,5)implementingcachingwi

PHPemailvalidationinvolvesthreesteps:1)Formatvalidationusingregularexpressionstochecktheemailformat;2)DNSvalidationtoensurethedomainhasavalidMXrecord;3)SMTPvalidation,themostthoroughmethod,whichchecksifthemailboxexistsbyconnectingtotheSMTPserver.Impl


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

Dreamweaver CS6
Visual web development tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

WebStorm Mac version
Useful JavaScript development tools
