0

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

});

4

1 回答 1

0

成功定义为

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

尝试

success: function (data) {
             alert('in success JSON');                   
             alert(data); //success
         },
于 2013-04-11T12:59:05.620 回答