javascript - Load variable from URL -
my example page url http://example.com/itemurl/?23 23 item number.
on page, need pull 23 , make variable can append url in ajax call xml file:
here 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 url in script https://example.com/getxml/23 i'm not sure how accomplish this.
the line url should this:
url: "https://example.com/getxml/"+window.location.search.substr(1),
Comments
Post a Comment