开发者

Saving Data from jQuery/EXT JS

开发者 https://www.devze.com 2023-02-03 06:26 出处:网络
When saving data from a form submit using jQuery/Ext JS what is the开发者_如何转开发 best approach?

When saving data from a form submit using jQuery/Ext JS what is the开发者_如何转开发 best approach?

Should the data be sent as an Array/List or JSON to the Server?


jQuery.ajax({
            url: 'page',
            cache: false,
            type: "post",
            data: ({id: 1, idUser: 000}),
            dataType: "html",
            async: true,
            success: function(data){
                alert(date);
            },
            error: function(XMLHttpRequest, textStatus, errorThrown) {
                alert(textStatus);
            }
        });


It really depends on your server side system/frameworks etc. For example, if you were sending values to a WCF Web Service, you could configure said web service to expect whatever you fancy sending.

However, saving as URL POST params will remove requirement to decode values on the server side.

IE: If you save as JSON, you'll have to decode that JSON on the server side before you can use the values.


Here's a EXT JS:

Ext.Ajax.request({
  loadMask: true,
  url: 'myfile.php',
  params: {id: "1"},
  success: function(resp) {
    // resp is the XmlHttpRequest object
    var options = Ext.decode(resp.responseText).options;

    Ext.each(options, function(op) {
      alert(op.message);
    }
  }
});
0

精彩评论

暂无评论...
验证码 换一张
取 消