【问题标题】:Load search form results inline with jQuery, instead of on a new page使用 jQuery 加载搜索表单结果,而不是在新页面上
【发布时间】:2011-09-17 11:10:24
【问题描述】:

我正在尝试为基于 Magento 的电子商务设置构建自定义搜索表单。

此搜索表单由几个(下拉)选择框组成。表单运行正常,但在您选择搜索值并提交表单后,您将被带到包含结果的新页面。

搜索页面网址:http://exampleshop.com/catalogsearch/advanced
结果页网址:http://exampleshop.com/catalogsearch/advanced/result/?color=red&size=large

我想做的是使用一些 jQuery 将搜索结果加载到表单下方的 div 中。

我已经搜索并找到了几个这样的例子,但我似乎无法找到任何地方。我在 Stack Overflow 上也遇到了一些类似的主题,但到目前为止,这里还没有对我有用。

感谢您对此提供的任何帮助或指导。

【问题讨论】:

    标签: php jquery ajax search magento


    【解决方案1】:

    http://api.jquery.com/load

    $('div').load(someUrl, opts);

    【讨论】:

      【解决方案2】:

      .load 是最简单的方法。它基本上调用一个程序,当它完成时,结果会加载到你想要的任何地方。最完整的形式是:

      $("#results").load("/search.php?keyword=" + $("#searchinput").val() + " #phpresult", showResults)
      

      将使用带有“searchinput”字段值的参数关键字调用search.php(您需要编码或其他)。当 search.php 页面完成搜索时,它可以将结果留在 id 为 'phpresult' 的容器中,这将替换调用程序的 'results' 容器中的内容。加载完成后,将调用函数“showResults”来执行您想做的任何事情。
      最简单的形式是

      $("#results").load("/search.php?keyword=" + $("#searchinput").val())
      

      它只是调用程序,整个结果将进入#results。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2012-02-06
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-10-14
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多