【问题标题】:How to pass values throught URL using ajax and jquery?如何使用 ajax 和 jquery 通过 URL 传递值?
【发布时间】:2016-06-03 22:05:16
【问题描述】:

所以我在 ajax-jquery 中通过 url 传递变量时遇到问题...我有这个:

function showBrand(brandId){
    $.ajax({ 
        url:'brandFilter.php',
        type:'POST',
        data: {brandId:brandId},
        dataType:'html',
        success:function(resultHTML){
            $("#filteredProducts").html(resultHTML); 
        }
    }); 
}

这在我只传递一个 brandId 时有效,这取决于用户点击了哪个链接。我添加了分页,所以我想每页显示 3 个产品,所以当用户点击页码时我必须同时传递 pageNumber 和 brandId ......你能帮帮我吗?我想应该是这样的

index.php?pageNumber=2&brandId=2

还是我错了?

【问题讨论】:

  • 只要data: {brandId:brandId, pageNumber: 1}。还是我错过了什么?

标签: jquery ajax pagination parameter-passing


【解决方案1】:

您可以添加多个数据或将其序列化并通过 ajax 作为传递,

function showBrand(brandId){
$.ajax({ 
    url:'brandFilter.php',
    type:'POST',
    data: {brandId:brandId, pageNumber:pageNumber},
    dataType:'html',
    success:function(resultHTML){
        $("#filteredProducts").html(resultHTML); 
    }
}); 

你也可以使用data: $("#form").serialize();
其中#form 是您在html 中的表单ID。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-04-29
    • 1970-01-01
    • 1970-01-01
    • 2021-05-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多