2011-09-06 10 views
1
function workprogress(){Ext.Ajax.request({ 
    url: 'communication.php', 
    success: noWork, 
    failure: yesWork 
    });} 
    function noWork() { 
      infoWindow.hide(); 
    } 
    function yesWork() { 
      infoWindow.show(); 
    } 

我想呼应响应文本到窗口。如何捕获来自php文件的响应文本?如何在ExtJS中获得成功的文本?

回答

3
function workprogress(){Ext.Ajax.request({ 
    url: 'communication.php', 
    success: function(result) { 
       var response = Ext.decode(result.responseText); 
       if (response.success) //success true 
       else //success false 
    } 
    failure: function() { 
      //requests fails completely due to other reasons, timeout ... 
    } 
1
Ext.Ajax.request({ 
     url: 'moo.php?id=1', 
     success: function(response, opts) { 
      var json = Ext.decode(response.responseText); 
      if(json.success){ 
       Ext.Msg.alert('Success','Logged out successfully..', function(){ 
        window.location.href = './'; 
       }); 
      } 
      else { 
       Ext.Msg.alert('Failure',json.error_msg); 
      } 
     }, 
     failure: function(response, opts) { 
      Ext.Msg.alert('server-side failure with status code ' + response.status); 
     } 
}); 

很容易:)

2
function workprogress(){ 
    Ext.Ajax.request({ 
     url: 'communication.php', 
     success: noWork, 
     failure: yesWork 
     }); 
} 

function noWork(resp) { 
    var text = resp.responseText; 
    infoWindow.hide(); 
} 

function yesWork() { 
    var text = resp.responseText; 
    infoWindow.show(); 
} 

您可能需要JSON首先解码响应文本,这取决于你的PHP从Ajax调用重复着。

1

最近使用此代码:

var xmlArea = new Ext.form.HtmlEditor({ 
     name : 'xml', 
     id : 'xml', 
     height : 700, 
     width : 480, 
     enableAlignments : false, 
     enableColors : false, 
     enableFont : false, 
     enableFontSize : false, 
     enableFormat : false, 
     enableLinks : false, 
     enableLists : false, 
     enableSourceEdit : false 
    }); 

...

success : function(responseObject) { 
         if(!win) { 
xmlArea.setValue(responseObject.responseText); 
           win = new Ext.Window({ 
            layout : 'fit', 
            title : 'Result', 
            width : 600, 
            height : 400, 
            closeAction : 'hide', 
            plain : true, 

            items : [xmlArea], 
           }); 
          } 
          win.show(this); 
         } 
相关问题