我有一个复选框,根据其检查状态,将附加"订阅"或者"取消订阅"到请求URL的末尾。问题是我无法将其应用到网址的末尾。
<form role="form" id="form" class="form-horizontal">
<div class="form-group selectors">
<div class="row">
<div class="col-md-2 portfolio-item">
<h5>Region</h5>
<select class="form-control" name="region" id="region" >
<option value="US" selected="selected">US</option>
<option value="UK">UK</option>
<option value="XS">XS</option>
<option value="XT">XT</option>
</select>
</div>
<div class="col-md-2 portfolio-item">
<h5>Duration</h5>
<select class="form-control" name="duration" id="duration" >
<option value="5" selected="selected">5 Minutes</option>
<option value="10">10 Minutes</option>
<option value="15">15 Minutes</option>
<option value="20">20 Minutes</option>
<option value="25">25 Minutes</option>
<option value="30">30 Minutes</option>
</select>
</div>
</div>
<input type="checkbox" id="status" name="status" />
</div>
</div>
</div>
`
<input type="checkbox" id="status" name="status" />
var input = document.querySelector('input[type=checkbox]');
var status = input.checked ? "subscribed" : "unsubscribed";
请求网址:
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")
});
我需要将"?subscribed=" + status
添加到请求网址的末尾,但它会破坏我的代码。
最终结果应如下所示:region/US/duration/15?subscribed=true
当我将复选框状态应用到网址的末尾时,如下所示:
"region/"+ (options.req.query.region ? options.req.query.region : "US") + "/duration/" + (options.req.query.duration ? options.req.query.duration : "5") + "?subscribed=" + status
我在终端获得ReferenceError: status is not defined
。