下面是我的jQuery的東西,它正確地調用REST服務和響應結果返回到AJAX成功事件。在AJAX中,變量值沒有更新
但是,每次執行時它都不會更新變量「SelectedVal」(document.getElementById('Text1').value)並保持相同,這是第一次設置的值。
它看起來像事件附加,並沒有更新每次click.How它可以解決?
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);
}
});
}
});
});
_ 「它不更新變量」 _ - 右。因爲你的代碼中沒有任何一點你會這樣做。你需要在你的'success'處理器中用響應的值做一些事情 - 離開上下文有點難以猜測要做什麼,但可能像'document.getElementById('Text1')。value = resp.someProperty ;'(如果你的REST服務正在返回JSON,那大概是JSON(一旦被解析)將有一個屬性是你想要的值)。 – nnnnnn 2013-04-11 12:44:05
你可以發佈你在上面調用函數的代碼嗎? – 2013-04-11 12:47:27
我認爲他意味着狀態變量。 – laktak 2013-04-11 13:00:01