【问题标题】:jquery step and send var data in php pagejquery步骤并在php页面中发送var数据
【发布时间】:2023-09-03 18:57:01
【问题描述】:

我使用 jquery 脚本步骤表单 http://www.jquery-steps.com/Examples

表单分为四步,最后一步我完成了一个打开警报窗口的按钮,但我想发送变量 post 或访问 php 页面

我换了

onFinished: function (event, currentIndex)   
                {
                    alert("Submitted!"); 
                }

我用 window.location 替换了警报

onFinished: function (event, currentIndex)  
                    {
                        window.location.href = "test_insert.php";  
                    }

但不要将任何数据传输到我的 php 页面

感谢您的帮助

【问题讨论】:

  • 这是因为您只是将用户重定向到页面“test_insert.php”,而不是在此页面上发布任何数据..
  • 感谢 goodface87 和 Vishal。我如何传输变量?我有像<input type="text" id="data1" name="data1" /><input type="text" id="data2" name="data2" /> 这样的输入,我知道我应该这样做code$.ajax({ type: "POST", url: "some.php", data: "name=John&location=Boston", success: function(msg){ alert( "Data Saved: " + msg ); } });` 我应该用什么来代替 "name=John&location=Boston"跨度>

标签: jquery forms post send


【解决方案1】:

我建议你使用 jQuery 的 ajax 函数,而不是尝试将整个窗口导航到你的 php 页面。

onFinished: function (event, currentIndex)  
{
  $.ajax({
    type: "POST",
    url: "test_insert.php",
    data: { yourParameterName: yourVariable }
  })
  .done(function( msg ) {
    alert( "Data Saved: " + msg );
  });
}

在数据部分,您只需发送 php 期望的任何内容。

【讨论】:

  • 感谢您的回答,我在 ..Form Wizard using jQuery Steps 的文档中找到了此解决方案...onFinished: function (event, currentIndex) { var form = $(this); form.submit(); } 表单数据已发送到我的 php 页面。