一些ajax帮助吗? [英] Some ajax help?

查看:85
本文介绍了一些ajax帮助吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个php脚本,该脚本接受一些用户形式的输入,并根据该输入将一些文件打包为zip.问题在于有时服务器会出错,因此所有表单数据都将丢失.有人告诉我可以改用ajax,以便用户甚至不必更改页面.我从未使用过ajax,而是查看 http://api.jquery.com/jQuery.ajax/没有ajax经验是很困难的.

I have a php script that takes some user form input and packs some files into a zip based on that input. The problem is that sometimes the server errors, so all the form data is lost. I was told I could use ajax instead so that the user never even has to change the page. I've never used ajax, and looking at http://api.jquery.com/jQuery.ajax/ without any experience in ajax is quite difficult.

页面上说您可以接受来自ajax调用的返回.如何在ajax调用的PHP文件中设置返回值?如果服务器因ajax调用而出错,我怎么知道?

The page says that you can accept returns from an ajax call. How do you set up returns in the PHP file for an ajax call? If the server errors with the ajax call, how will I know?

edit:另外,是否可以通过javascript和jquery发送ajax请求,就好像它是已提交的表单一样?

edit: Also, is there a way to send an ajax request with javascript and jquery as if it were a submitted form?

推荐答案

如何在PHP文件中设置退货

只是在页面中回显,它将作为响应返回

just echo it in ajax page that will return as response

简单教程

client.php

$.post('server.php',({parm:"1"}) function(data) {
  $('.result').html(data);
});

server.php

<?php

echo $_POST['parm'];

?>

结果将为1

编辑OP注释 是否有一种使用ajax的方式,就像您正在提交表单一样

是的,有

  • You can use plugins like jQuery form
  • Using submit
  • If you using jquery validation plugin, you can use submit handler option

使用汇款

$('#form').submit(function() {
 //your ajax call
  return false;
});

这篇关于一些ajax帮助吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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