在AJAX中,不更新变量值

时间:2013-04-11 12:41:30

标签: javascript json jquery velocity

下面是我的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); 
            }
        });
}                                                       
});

});

1 个答案:

答案 0 :(得分:0)

成功定义为

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

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