mercredi 29 juillet 2015

Applying value of checkbox to API request URL

I have a checkbox which, based on its checked status, will append either "subscribed" or "unsubscribed" to the end of a request URL. The issue is that I can't get it to apply to the end of the URL, but it is going to the query string(no helpful).

<input type="checkbox" id="status" name="status" />

var input = document.querySelector('input[type=checkbox]');
var status = input.checked ? "subscribed" : "unsubscribed";

request url:

dataStore({
   callback:callback,
   cacheExp: 0,
   apiUrl: "region/"+ (options.req.query.region ? options.req.query.region : "US") + "/duration/" + (options.req.query.duration ? options.req.query.duration : "5")
});

I need to add "?subscribed=" + status to the end of the request url, but it is breaking my code.

The end results should look like this: region/US/duration/15?subscribed=true

When I apply the checkbox status to the end of the url like so:

"region/"+ (options.req.query.region ? options.req.query.region : "US") + "/duration/" + (options.req.query.duration ? options.req.query.duration : "5") + "?subscribed=" + status

I get ReferenceError: status is not defined in the terminal.




Aucun commentaire:

Enregistrer un commentaire