通过jquery .ajax完成时,存储POST的变量名称是什么? [英] what is the variable name that stores a POST when done through jquery .ajax?

查看:85
本文介绍了通过jquery .ajax完成时,存储POST的变量名称是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当通过POST定期提交表单时,表单值的内容存储在$ _POST中,然后在.submit上使用jquery .ajax函数.什么是用于检索php文件中数据的变量?处理表格?

when a form is submitted regularly via POST the contents of the values of the form are stored in $_POST but then the jquery .ajax function is used on an .submit what is the variable used to retrieve the data in the php file that processes the form?

推荐答案

jQuery $.ajax函数在选项中使用type参数,该参数设置请求是通过post还是get完成.默认为get.

The jQuery $.ajax function takes a type parameter in the options, which sets whether the request should be done via post or get. It defaults to get.

如果将其设置为get,则可以通过$_GET超全局变量获取PHP中的信息.另一方面,如果将其设置为post(可能是您想要的),则可以通过$_POST进行访问.

If it's set to get, you can get to the info in PHP via the $_GET superglobal. On the other hand, if you set it to post (which is probably what you want), you can get to it via $_POST.

示例:

$.ajax({
  url: 'ajax/test.html',
  type: 'post',
  data: {firstName: 'John', lastName: 'Doe' },
  success: function(data)
  {
    alert( 'We have data: ' + data.toString() );
  }
});

这篇关于通过jquery .ajax完成时,存储POST的变量名称是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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