【问题标题】:Sweetalert2 Swal.mixin - is it possible to extract input data to json / php?Sweetalert2 Swal.mixin - 是否可以将输入数据提取到 json / php?
【发布时间】:2020-01-22 03:03:52
【问题描述】:
Using this code:
Swal.mixin({
  input: 'text',
  confirmButtonText: 'Next →',
  showCancelButton: true,
  progressSteps: ['1', '2', '3']
}).queue([
  {
    title: 'Question 1',
    text: 'Chaining swal2 modals is easy'
  },
  'Question 2',
  'Question 3'
]).then((result) => {
  if (result.value) {
    const answers = JSON.stringify(result.value)
    Swal.fire({
      title: 'All done!',
      html: `
        Your answers:
        <pre><code>${answers}</code></pre>
      `,
      confirmButtonText: 'Lovely!'
    })
  }
})

在这种情况下,我的回答:

["1","1","2"]

它怎么会接收到一个php文件中传入的值呢? 我对这两个主题都不太了解,但我正在经历这种需求。 对不起,对不起我的英语。

【问题讨论】:

  • 如果我理解正确你在php 文件中有数据并且你想在你的js 代码中获取它所以你需要使用ajax 搜索它
  • @Joseph 实际上,我想将这些数据从该代码传递给 PHP。我只是不太明白如何做到这一点。你能指导我吗?我搜索这个,发现这个帖子:stackoverflow.com/questions/50847738/… 只有没有任何解决方案。

标签: javascript php arrays json sweetalert2


【解决方案1】:

更新:

使用此代码:Sweet Alerts - Queue form 为 Swal.fire 更改 swal

  var strAns1;
    var strAns2;

    swal.mixin({
      input: 'text',
      confirmButtonText: 'Next &rarr;',
      showCancelButton: true,
      progressSteps: ['1', '2', '3']
    }).queue([
      {
        title: 'Question 1',
        text: 'Chaining swal2 modals is easy',
        preConfirm: function(value)
                {
                    strAns1= value;
                }
      },

      {
        title: 'Question 2',
        text: 'Chaining swal2 modals is easy',
        preConfirm: function(value)
                {
                    strAns2= value;
                }
      }
    ]).then((result) => {
      if (result.value) {
        Swal.fire({
          title: 'All done!',
          html:
            'Your answers: <pre>' +
              JSON.stringify(result) +
            '<pre>Answer1- ' + strAns1+
            '<pre>Answer2- ' + strAns2+
            '</pre>',
          confirmButtonText: 'Lovely!'
        })
      }
    })

改变

swal({
      title: 'All done!',
      html:
        'Your answers: <pre>' +
          JSON.stringify(result) +
        '<pre>Answer1- ' + strAns1+
        '<pre>Answer2- ' + strAns2+
        '</pre>',
      confirmButtonText: 'Lovely!'
    })
  }
})

To

Swal.fire({
      title: 'All done!',
      html:
        'Your answers: <pre>' +
          JSON.stringify(result) +
        '<pre>Answer1- ' + strAns1+
        '<pre>Answer2- ' + strAns2+
        '</pre>',
      confirmButtonText: 'Lovely!'
    })
  }
})

我得到这样的结果:

{"value":["adf","fffff"]}
Answer1- adf
Answer2- fffff

现在我可以将它传递给 php 吗? 比如说? 非常感谢。

【讨论】:

    猜你喜欢
    • 2016-02-23
    • 1970-01-01
    • 1970-01-01
    • 2016-02-07
    • 2017-07-07
    • 1970-01-01
    • 2013-04-18
    • 2020-12-09
    • 1970-01-01
    相关资源
    最近更新 更多