简体   繁体   English

如何更改网址

[英]How to change the url

I want to change the URL of the update operation. 我想更改更新操作的URL。 The end point of the URL should be gotten from an input. URL的终点应从输入中获取。 How can I achieve this? 我该如何实现? The following doesn't work. 以下无效。

  $(document).ready(function(){ $.fn.serializeObject = function() { var o = {}; var a = this.serializeArray(); $.each(a, function() { if (o[this.name] !== undefined) { if (!o[this.name].push) { o[this.name] = [o[this.name]]; } o[this.name].push(this.value || ''); } else { o[this.name] = this.value || ''; } }); return {"issue":o}; }; 
 <form role="form"> <div class="form-group input-group"> <div class="row"> <div class="col-md-6"> <label>Issue ID * &nbsp;</label> <select class="form-control selectclass" id="issueid"></select> </div> <div class="col-md-6"> <label>Tracker * &nbsp;</label> <select class="form-control" name="tracker" id="tracker"> <option value="1">Bug</option> <option value="2">Feature</option> <option value="3">Support</option> </select> </div> </div> </div> <div class="form-group"> <label>Subject &nbsp;</label> <input class="form-control" placeholder="Issue Subject" name="subject" id="subject"> </div> <div class="form-group"> <label>Description</label> <textarea class="form-control" rows="6" name="description" id="description"></textarea> </div> <button type="submit" id="submit" class="btn btn-default">Submit Button</button> <button type="reset" class="btn btn-default">Reset Button</button> </form> 

 $('#submit').on('click', function(){ var x=document.getElementById('issueid').value; $.ajax({ type : 'PUT', url: 'http://localhost/redmine/issues'+ x +'.json', contentType:'application/json', data:JSON.stringify($('form').serializeObject()), // post data || get data success : function(msg, status, jqXHR) { console.log(msg, status, jqXHR); }, error: function(xhr, resp, text) { console.log(xhr, resp, text); } }) console.log(x); }); }); 

Inputs are gotten from a form and sent to Redmine API. 输入是从表单获取的,然后发送到Redmine API。 URL should look like below, http://localhost/redmine/issues/2.json URL应该如下所示, http://localhost/redmine/issues/2.json

When dynamically populating your id="issueid" select make sure that you properly set the value attribute of the options: 动态填充id="issueid" ,请确保正确设置选项的value属性:

$('.selectclass').append('<option value="' + value.id + '">' + value.id + '<option>');

Also fix the url for your next AJAX request by adding a trailing / after issues : 还可以通过添加尾随/后面的issues修复下一个AJAX请求的网址:

url: 'http://localhost/redmine/issues/' + x + '.json'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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