0

My example page url is http://example.com/itemurl/?23 where 23 is the item number.

On that page, I need to pull that 23 and make it a variable so I can append it to the url in an Ajax call to get an xml file:

Here is my script:

<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>

I need the url in the script to be https://example.com/getxml/23 but I'm not sure how to accomplish this.

Merlin7591
  • 99
  • 5

1 Answers1

1

The line with url should look like this:

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