您好,欢迎访问一九零五行业门户网

PHP如何接受ajax的post 表单并分行保存TXT呢

js代码如下
function submitapply() { var form = global.getelement(#submitform); var username = global.getelement(form, 'input[name=name]').value; var mobile = global.getelement(form, 'input[name=tel]').value; var position = global.getelement(form, 'input[name=position]').value; var company = global.getelement(form, 'input[name=company]').value; var actid = global.getelement(form, 'input[name=actid]').value; if (global.isnullorwhitesapce(username)) { global.tip.tiperror(姓名必须填写); return; } if (global.isnullorwhitesapce(mobile)) { global.tip.tiperror(手机必须填写); return; } if (/^1[3|4|5|8][0-9]\d{4,8}$/.test(mobile) == false) { global.tip.tiperror(手机格式不正确); return; } var ajaxrequest = new httpajaxrequest(); ajaxrequest.ajax({ datatype: 'json', url: '', data: { name: username, mobile: mobile, companyname: company, position: position, actid: actid }, successed: onsubmitappplysuccesse, error: function () { global.tip.tiperror('提交失败!'); globalplayer.disablenext(); } });}/** * 名称:申请提交成功 */function onsubmitappplysuccesse(data) { if (data.code == 0) { global.tip.tipmessage('提交成功!'); var form = global.getelement(#submitform); globalplayer.enablenext(); globalplayer.playnext(); form.reset(); } else { global.tip.tiperror('提交失败!' + data.message); globalplayer.disablenext(); }}
哪个好人帮我写个完整的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:
$name = $_post['name'];$mobile = $_post['mobile'];$companyname = $_post['companyname'];$actid = $_post['actid'];$position = $_post['position']; $str =$name. \n.$mobile.\n.$companyname.\n.$actid.\n.$position;$h = fopen('./t.txt','w');fwrite($h,$str);fclose($h);

在贴吧看到你了。。
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:
$name = $_post['name'];$mobile = $_post['mobile'];$companyname = $_post['companyname'];$actid = $_post['actid'];$position = $_post['position']; $str =$name. \n.$mobile.\n.$companyname.\n.$actid.\n.$position;$h = fopen('./t.txt','w');fwrite($h,$str);fclose($h);

大神啊 接收端不错 就是这个js 发不出去数据 一直提交的是空数据是怎么回事呀 你没有指定工作方式,默认应该的 get
用 $_post 当然收不到数据
其它类似信息

推荐信息