www.webdeveloper.com
Results 1 to 5 of 5

Thread: [RESOLVED] post serializeArray()

  1. #1
    Join Date
    Nov 2010
    Posts
    23

    resolved [RESOLVED] post serializeArray()

    I need some assistance with sending JSON to the server. When I make this post using $('#trfFilterForm').serialize() I can view that URL-encoded string on my server (cherrypy). When I make the post using $('#trfFilterForm').serializeArray() the server responds with status of 400 Bad Request (I'm not even touching the JSON on the server side at this point). Is there something else I need to be doing to the JSON data before I post it?


    Code:
    ...
    var filters = $('#trfFilterForm').serializeArray();
    //var filters = $('#trfFilterForm').serialize();
    ...
    $.post('getMarkers', {
        filters: filters
    }, function(data){  
             ...
    }, 'json');

  2. #2
    Join Date
    Feb 2003
    Location
    Michigan, USA
    Posts
    5,774

  3. #3
    Join Date
    Nov 2010
    Posts
    23
    It returns an Array of Objects (name, value pairs).
    http://api.jquery.com/serializeArray/

  4. #4
    Join Date
    Nov 2010
    Posts
    23
    So it looks like serializeArray is including extra information in each object in the array. Could this be the cause of the error? The jquery docs do not mention this __proto__ object.

    Code:
    [Object
    name: "trfHVFilter"
    value: "6.6"
        __proto__: Object
        __defineGetter__: function __defineGetter__() { [native code] }
        __defineSetter__: function __defineSetter__() { [native code] }
        __lookupGetter__: function __lookupGetter__() { [native code] }
        __lookupSetter__: function __lookupSetter__() { [native code] }
        constructor: function Object() { [native code] }
        hasOwnProperty: function hasOwnProperty() { [native code] }
        isPrototypeOf: function isPrototypeOf() { [native code] }
        propertyIsEnumerable: function propertyIsEnumerable() { [native code] }
        toLocaleString: function toLocaleString() { [native code] }
        toString: function toString() { [native code] }
        valueOf: function valueOf() { [native code] }
    ]

  5. #5
    Join Date
    Nov 2010
    Posts
    23
    Here is the content returned instead of the JSON array I would normally expect.

    HTML Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8"></meta>
        <title>400 Bad Request</title>
        <style type="text/css">
        #powered_by {
            margin-top: 20px;
            border-top: 2px solid black;
            font-style: italic;
        }
    
        #traceback {
            color: red;
        }
        </style>
    </head>
        <body>
            <h2>400 Bad Request</h2>
            <p>Unexpected body parameters: filters[0][value], filters[0][name], filters[1][value], filters[1][name]</p>
            <pre id="traceback">Traceback (most recent call last):
      File "C:\Python27\lib\site-packages\cherrypy\_cprequest.py", line 606, in respond
        cherrypy.response.body = self.handler()
      File "C:\Python27\lib\site-packages\cherrypy\_cpdispatch.py", line 27, in __call__
        test_callable_spec(self.callable, self.args, self.kwargs)
      File "C:\Python27\lib\site-packages\cherrypy\_cpdispatch.py", line 137, in test_callable_spec
        "%s" % ", ".join(extra_body_params))
    HTTPError: (400, 'Unexpected body parameters: filters[0][value], filters[0][name], filters[1][value], filters[1][name]')
    </pre>
        <div id="powered_by">
        <span>Powered by <a href="http://www.cherrypy.org">CherryPy 3.1.2</a></span>
        </div>
        </body>
    </html>
    and the headers

    Code:
    Request URL:http://localhost:8080/getMarkers
    Request Method:POST
    Status Code:400 Bad Request
    Request Headers
    Accept:application/json, text/javascript, */*
    Content-Type:application/x-www-form-urlencoded
    Origin:http://localhost:8080
    Referer:http://localhost:8080/
    User-Agent:Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/534.7 (KHTML, like Gecko) Chrome/7.0.517.44 Safari/534.7
    X-Requested-With:XMLHttpRequest
    Form Data
    filters%5B0%5D%5Bname%5D:trfConnFilter
    filters%5B0%5D%5Bvalue%5D:DELTA-WYE
    filters%5B1%5D%5Bname%5D:trfHVFilter
    filters%5B1%5D%5Bvalue%5D:4.16
    Response Headers
    Content-Length:1359
    Content-Type:text/html
    Date:Tue, 07 Dec 2010 20:19:43 GMT
    Server:CherryPy/3.1.2
    Last edited by sNagheenanajar; 12-07-2010 at 04:39 PM. Reason: include the headers

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles