jQuery.get 方法未按预期工作


jQuery.get method is not working as expected

我在javascript方法中有一个数组。我想在单独的 php 文件中访问它。我正在尝试jQuery.get方法。这是代码:

<script>
function Quantity(){
    var count = document.getElementById('hidden').value;
    alert(count);
    var Quantity=new Array();
    var i=0;
    for(i=0; i<count; i++) {
       Quantity[i]=document.getElementById(i).value;
    }
    document.getElementById('hdnQuantityArray').value = Quantity;
    jQuery.get("CalculateTotal.php", Quantity);
    return false;
}
</script>

我正在使用隐藏字段hdnQuantityArray通过 GET 发送此数组。问题是,这段代码没有将我重定向到文件CalculateTotal.php。相反,它与包含隐藏字段值的 URL 保持在同一页面上。

如果我在这里做错了什么,请指导我。否则建议我一个替代方案。

不确定它会起作用...

取代

jQuery.get("CalculateTotal.php", Quantity);

location.href="CalculateTotal.php?Quantity"+$(Quantity).serializeArray()

如果你想重定向到那个页面,你只需要:

window.location = "CalculateTotal.php";

jQuery.get用于将该页面作为字符串检索。因此,您可以检索它,然后在页面的某些内容区域中使用它,例如:

var totalContent = jQuery.get("CalculateTotal.php", Quantity);
$('#some_content_div').html(totalContent);