简体   繁体   中英

How to pass a variable into the middle of $.ajax url with JQuery

I'm passing a variable from one function into another, then need that variable set into the URL for the next ajax call, I thought this would be easy but nope.

Here's my code, I removed my dev key from the end of the call.

 function Transmission(styleID){ $.ajax({ url: "https://api.edmunds.com/api/vehicle/v2/transmissions/" + styleID + "?fmt=json&api_key=REMOVED",// setting styleID number in URL with passed variable //force to handle it as text dataType: "text", success: function(data) { var json = $.parseJSON(data); $('#car_transmission').find("option[text=" + json.transmissionType + "]").attr("selected", true); }}); } 

It's failing, but if I hard code the styleID it works just fine, all of the searches I did were to add variables to the end of the URL. Any thoughts are appreciated!!

Thank you !!!!!! d

如何将styleID + "?fmt=json&api_key=REMOVED"更改为styleID + "?fmt="+json&"api_key="+REMOVED

OK, I solved it, I was using the wrong URL, the VIN lookup gives the StyleID, the StyleID lookup gives the transmissionID, I was calling the URL for the transmissionID API, the URL's were next to each other on the webpage for edmunds API.

So thank you everyone for trying to help!!!

The moral of the story is try not to program while tired and multitasking!! lol

d

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM