Home > Backend Development > PHP Tutorial > PHP怎么接受ajax的post 表单并分行保存TXT呢

PHP怎么接受ajax的post 表单并分行保存TXT呢

WBOY
Release: 2016-06-13 12:17:36
Original
999 people have browsed it

求助 PHP如何接受ajax的post 表单并分行保存TXT呢
JS代码如下

function SubmitApply() {<br />    var form = Global.GetElement("#submitForm");<br />    var UserName = Global.GetElement(form, 'input[name="Name"]').value;<br />    var Mobile = Global.GetElement(form, 'input[name="Tel"]').value;<br />    var Position = Global.GetElement(form, 'input[name="Position"]').value;<br />    var Company = Global.GetElement(form, 'input[name="Company"]').value;<br />    var ActId = Global.GetElement(form, 'input[name="Actid"]').value;<br />    if (Global.IsNullOrWhitesapce(UserName)) {<br />        Global.Tip.TipError("姓名必须填写");<br />        return;<br />    }<br />    if (Global.IsNullOrWhitesapce(Mobile)) {<br />        Global.Tip.TipError("手机必须填写");<br />        return;<br />    }<br />    if (/^1[3|4|5|8][0-9]\d{4,8}$/.test(Mobile) == false) {<br />        Global.Tip.TipError("手机格式不正确");<br />        return;<br />    }<br />    var ajaxRequest = new HttpAjaxRequest();<br />    ajaxRequest.ajax({<br />        dataType: 'json',<br />        url: '',<br />        data: { name: UserName, mobile: Mobile, companyname: Company, position: Position, actid: ActId },<br />        successed: OnSubmitAppplySuccesse,<br />        error: function () {<br />            Global.Tip.TipError('提交失败!');<br />            GlobalPlayer.DisableNext();<br />        }<br />    });<br />}<br /><br />/**<br /> * 名称:申请提交成功<br /> */<br />function OnSubmitAppplySuccesse(data) {<br />    if (data.Code == 0) {<br />        Global.Tip.TipMessage('提交成功!');<br />        var form = Global.GetElement("#submitForm");<br />        GlobalPlayer.EnableNext();<br />        GlobalPlayer.PlayNext();<br />        form.reset();<br />    } else {<br />        Global.Tip.TipError('提交失败!' + data.Message);<br />        GlobalPlayer.DisableNext();<br />    }<br />}
Copy after login


哪个好人帮我写个完整的PHP接受源码吧 本人PHP小白(已哭晕)
------解决思路----------------------
在贴吧看到你了。。


ajaxRequest.ajax({
dataType: 'json',
url: './save_to_txt.php',
data: { name: UserName, mobile: Mobile, companyname: Company, position: Position, actid: ActId },
successed: OnSubmitAppplySuccesse,
error: function () {
Global.Tip.TipError('提交失败!');
GlobalPlayer.DisableNext();
}
});


save_to_txt.php:
<br />$name = $_POST['name'];<br />$mobile = $_POST['mobile'];<br />$companyname = $_POST['companyname'];<br />$actid = $_POST['actid'];<br />$position = $_POST['position'];<br /> $str =$name. "\n".$mobile."\n".$companyname."\n".$actid."\n".$position;<br />$h = fopen('./t.txt','w');<br />fwrite($h,$str);<br />fclose($h);<br />
Copy after login

------解决思路----------------------
你没有指定工作方式,默认应该的 GET
用 $_POST 当然收不到数据

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template