【问题标题】:How to pass php variable to function in separate file and get results back without submitting the form?如何将 php 变量传递给单独的文件并在不提交表单的情况下返回结果?
【发布时间】:2017-09-20 10:38:34
【问题描述】:

我使用过汽车销售网站。用户可以发布他们的汽车出售。我希望用户在不提交来自的情况下单击预期价格字段时应该能够看到他们汽车的预期价格。函数输入将作为变量传递。见下图

【问题讨论】:

  • 所以....使用 ajax?
  • 你可以使用$_SESSION
  • 不要认为php是正确的方法。为什么你不像 Manav 告诉你的那样使用 JS/jaax

标签: javascript php jquery wordpress


【解决方案1】:

搜索 ajax。例如(使用 jQuery)

$.ajax({ url: "website.com/phpfile.php?var=" + encodeURIComponent(value),
    cache: false,
    timeout: 10000,
    success: function(response)
    {
         // do something with the result, or omit the whole success if not needed
    },
    error: function(jqXHR, textStatus, errorThrown)
    {
         // notify user about error?
    }
});

有更简单、更有针对性的版本,例如 $.post 或 $.get 在这里查看:http://api.jquery.com/category/ajax/

【讨论】:

    猜你喜欢
    • 2016-11-24
    • 1970-01-01
    • 2019-09-05
    • 2013-07-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多