簡體   English   中英

在AJAX中,變量值不會更新

[英]In AJAX, variable value is not updated

以下是我的jquery內容,調用REST服務並使其響應結果返回AJAX成功事件是正確的。

但是,每次執行時,它都不會更新變量“ 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); 
            }
        });
}                                                       
});

});

成功定義為

Type: Function( PlainObject data, String textStatus, jqXHR jqXHR )

嘗試

success: function (data) {
             alert('in success JSON');                   
             alert(data); //success
         },

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM