jquery - How to pass a URL parameter in an ajax() call -
i have single page (products) responds url parameters , displays information accordingly.
here examples:
http://www.mysupersite.com/products
http://www.mysupersite.com/products/buy
http://www.mysupersite.com/products/buy/computers
these user-friendly urls. url parameters "buy" , "computers".
i need pass parameters from current page in ajax() server knows types of information send e.g.
$.ajax({ type: "post", url: "/cfc/getsomeproducts", datatype: "html", data: { //psuedo code below... productcategory: "buy", producttype: "computers" } })
to clarify, if on /products/buy
, need send productcategory: 'buy'
. if on /products/buy/computers
, productcategory: 'buy', producttype: 'computers'
.
how achieve this?
var url = document.location.pathname; var values = url.split("/"); $.ajax({ type: "post", url: "/cfc/getsomeproducts", datatype: "html", data: { productcategory: values[2], producttype: values[3] } })
Comments
Post a Comment