Results 1 to 2 of 2

Thread: Ext.ajax.request GET + Json in query string

  1. #1
    Sencha User
    Join Date
    May 2017
    Posts
    39
    Answers
    9

    Default Answered: Ext.ajax.request GET + Json in query string

    How to send a json in ajax get using Ext.ajax.request. Here a example doing with jquery $.get('http://some.endpoint.com',{location: {abc: 1, two: 2}, type: 1},function(data){})

    How can I do the same in Ext.ajax.request() ?

  2. I did this way

    Code:
    var serializeObj = function(obj, prefix) {
          //{a:1,b:2}
          //return (Ext.os.is.Android ? encodeURIComponent(JSON.stringify(params)) : params)
    
    
          var str = [], p;
          for(p in obj) {
            if (obj.hasOwnProperty(p)) {
              var k = prefix ? prefix + "[" + p + "]" : p, v = obj[p];
              str.push((v !== null && typeof v === "object") ?
                this.serializeObj(v, k) :
                encodeURIComponent(k) + "=" + encodeURIComponent(v));
            }
          }
          return str.join("&");
        }
    
    var params = serializeObj( {location: {abc: 1, two: 2}, type: 1} )
    
    Ext.Ajax.request({
                    url: '...',
                    withCredentials: false,
                    useDefaultXhrHeader: false,
                    method: 'GET',
                    params: params,
                    callback: function(options, success, response) {
                    }
                });

  3. #2
    Sencha User
    Join Date
    May 2017
    Posts
    39
    Answers
    9

    Default

    I did this way

    Code:
    var serializeObj = function(obj, prefix) {
          //{a:1,b:2}
          //return (Ext.os.is.Android ? encodeURIComponent(JSON.stringify(params)) : params)
    
    
          var str = [], p;
          for(p in obj) {
            if (obj.hasOwnProperty(p)) {
              var k = prefix ? prefix + "[" + p + "]" : p, v = obj[p];
              str.push((v !== null && typeof v === "object") ?
                this.serializeObj(v, k) :
                encodeURIComponent(k) + "=" + encodeURIComponent(v));
            }
          }
          return str.join("&");
        }
    
    var params = serializeObj( {location: {abc: 1, two: 2}, type: 1} )
    
    Ext.Ajax.request({
                    url: '...',
                    withCredentials: false,
                    useDefaultXhrHeader: false,
                    method: 'GET',
                    params: params,
                    callback: function(options, success, response) {
                    }
                });

Similar Threads

  1. Not able to PUT json array in Ext.ajax.request
    By zjda in forum Ext: Discussion
    Replies: 2
    Last Post: 4 Feb 2013, 2:08 PM
  2. Ext.Ajax.request, JSON is not POST
    By spiteful_troll in forum Ext: Q&A
    Replies: 2
    Last Post: 10 Sep 2012, 10:46 PM
  3. JSON in ajax request
    By dedoz in forum Ext: Q&A
    Replies: 2
    Last Post: 8 May 2012, 6:52 AM
  4. Replies: 2
    Last Post: 13 Aug 2009, 8:49 AM
  5. Grid Json and Ajax.request
    By gcorgnet in forum Ext 1.x: Help & Discussion
    Replies: 2
    Last Post: 10 Oct 2007, 6:00 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •