以下は私のjqueryのものです。RESTサービスを呼び出すと正しく機能し、応答結果はAJAX Successイベントに戻ります。
ただし、実行するたびに、変数「SelectedVal」(document.getElementById('Text1').value) は更新されず、最初に設定された値のままです。
イベントが添付され、クリックごとに更新されないように見えます。どのように解決できますか?
jQuery(document).ready(function() {
var selectedVal = '';
var date = new Date();
var d = date.getDate();
var m = date.getMonth();
var y = date.getFullYear();
var calendar = jQuery('#calendar').fullCalendar({
header: {
left: 'prev,next today',
center: 'Plan Issues',
right: 'month,agendaWeek,agendaDay'
},
selectable: true,
selectHelper: true,
select: function(start, end, allDay) {
AJS.$(document).ready(function() {
var dialog = new AJS.Dialog({
width: 400,
height: 300,
id: "planissues-dialog",
closeOnOutsideClick: true
});
// PAGE 0 (first page)
// adds header for first page
dialog.addHeader("Plan Issues");
// add panel 1
dialog.addPanel("Issues Planning", "<table><tr><td>Enter issues ID (separated by comma):</td><td><input id='Text1' type='text' /></td></tr></table>", "panel-body"); //PROBLEM: "Text1" control is added here in dialog.
dialog.addButton("Submit", function (dialog)
{
selectedVal = document.getElementById('Text1').value; //PROBLEM:This returns every time same value even though, entering different value while dialog is popup. it preserve same value which was enter during first time and then after on each consequence , it remains same value.
if (selectedVal != '') {
alert(selectedVal); // PROBLEM: alert shows same value which set at first time.
var url = "http://localhost:2990/jira/rest/restresource/1.0/message/save/" + selectedVal;
jQuery.ajax({
type: "POST",
url: url,
contentType: "application/json",
dataType: "json",
data: "finaldatapassed",
cache: false,
success: function (resp, status, xhr) {
alert('in success JSON');
alert(status); //success
},
error: function(resp, status, xhr){
alert('in error json');
alert("Error: " + resp.e);
}
});
}
});
});