AJAX POST组的PHP表单变量

编程入门 行业动态 更新时间:2024-10-28 12:30:49
本文介绍了AJAX POST组的PHP表单变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试将一组表单参数发送到PHP脚本进行处理.

I am trying to send a group of form parameters over to a PHP script for processing.

我以前曾经使用$.post做过这样的事情,但是现在我试图通过使用$.ajax来严格完成它.

I've previously done something like this using $.post, but now I'm trying to get it done strictly by using $.ajax.

这是应该将所有变量发送到PHP脚本的jQuery click事件:

Here is the jQuery click event that is supposed to send all of the variables to the PHP script:

$('.searchSubmit').on('click', function() { var searchCriteria = { import_bill: $('#import_bill').val(), import_ramp: $('#import_ramp').val(), import_delivery: $('#import_delivery').val(), // few more form parameters }; $.ajax({ url: 'api/railmbs.php', // process script type: 'POST', data: searchCriteria, // parameter group above dataType: 'html' // had this set to json, but only got fail success: function(data, textStatus, jqXHR) { console.log(data); }, error: function(jqHHR, textStatus, errorThrown) { console.log('fail'); } }); });

这是一个名为railmbs.php的PHP脚本:

Here is the PHP script, called railmbs.php:

<?php if(isset($_POST['searchCriteria'])) { $value = $_POST['searchCriteria']; $_SESSION['where'] = ""; $import_bill = mysqli_real_escape_string($dbc, trim($value['import_bill'])); $import_ramp = mysqli_real_escape_string($dbc, trim($value['import_ramp'])); $import_delivery = mysqli_real_escape_string($dbc, trim($value['import_delivery'])); echo $import_bill; // just trying to echo anything at this point } ?>

不确定我在做什么错.如果在上述IF之前输入echo hello,则控制台将相应输出.但是我似乎无法从IF内部获得任何东西给echo.

Not sure what I am doing wrong. If I echo hello before the IF above, the console will output accordingly. But I cannot seem to get anything to echo from inside the IF.

有人看到我的错误吗?

推荐答案

您没有设置"searchCriteria"变量.

You are not setting the "searchCriteria" variable.

更改此:

$('.searchSubmit').on('click', function() { var searchCriteria = { import_bill: $('#import_bill').val(), import_ramp: $('#import_ramp').val(), import_delivery: $('#import_delivery').val(), // few more form parameters }; $.ajax({ url: 'api/railmbs.php', // process script type: 'POST', data: searchCriteria, // parameter group above dataType: 'html' // had this set to json, but only got fail success: function(data, textStatus, jqXHR) { console.log(data); }, error: function(jqHHR, textStatus, errorThrown) { console.log('fail'); } }); });

收件人:

$('.searchSubmit').on('click', function() { var data = { searchCriteria: { import_bill: $('#import_bill').val(), import_ramp: $('#import_ramp').val(), import_delivery: $('#import_delivery').val(), // few more form parameters } }; $.ajax({ url: 'api/railmbs.php', // process script type: 'POST', data: data, // parameter group above dataType: 'html' // had this set to json, but only got fail success: function(data, textStatus, jqXHR) { console.log(data); }, error: function(jqHHR, textStatus, errorThrown) { console.log('fail'); } });

更多推荐

AJAX POST组的PHP表单变量

本文发布于:2023-10-10 11:58:49,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1478608.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:表单   变量   AJAX   POST   PHP

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!