gpt4 book ai didi

javascript - 从 URL 加载变量

转载 作者:行者123 更新时间:2023-12-03 09:37:42 25 4
gpt4 key购买 nike

我的示例页面网址是 http://example.com/itemurl/?23其中 23 是商品编号。

在该页面上,我需要提取 23 并将其设为变量,以便我可以将其附加到 Ajax 调用中的 url 中以获取 xml 文件:

这是我的脚本:

<script>
$(document).ready(function () {
$.ajax({
type: "Get",
url: "https://example.com/getxml/",
dataType: "xml",
success: xmlParser
});
});

function xmlParser(xml) {

$(xml).find("product").each(function () {

$(".prod_title").append('<h1>' + $(this).find("item_name").text() + '</h1><span>' + $(this).find("short_description").text() + '</span><ol class="breadcrumb"><li><a href="#">Browse Products</a></li><li><a href="#">Your Dashboard</a></li></ol>');
$(".category").append('<div class="cat">'+ $(this).find("category_name").text() +'<div>');
$(".product-rating").append('<i class="icon-star3">'+ $(this).find("no_of_units").text() +' Units Available</i>');
$(".product-price").append('<ins>ARV: $'+ $(this).find("item_price").text() +' </ins>');
$(".product-image").append('<img src="'+ $(this).find("image_url").text() +'" alt="example_product"/>');
$(".exp-date").append('<li><i class="icon-caret-right"></i> Expires On: '+ $(this).find("prod_exp").text() +'</li></div>');
$(".posted_in").append('Category: '+ $(this).find("category_name").text() );
$(".prod_description").append('<p>'+ $(this).find("full_description").text() +'</p>');


});

}</script>

我需要脚本中的 url 为 https://example.com/getxml/23但我不知道如何实现这一点。

最佳答案

带有 url 的行应如下所示:

url: "https://example.com/getxml/"+window.location.search.substr(1),

关于javascript - 从 URL 加载变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31281513/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com