• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

“no element found” error when using JSON stringify method in jQuery ajax call

 
Ranch Hand
Posts: 67
1
Spring Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I want to update a section of a page using ajax when an image is clicked. When the image is clicked I pull values from a jQuery DataTable to populate an object. Then I call my action and pass in a JSON string of the object using `JSON.stringify()`.



However, calling the `ajax` function results in an error in the javascript console that only says "no element found". When I check the network activity it tries to hit the correct url, but returns a `400 error`.

I am sparing the back end details because I believe something in the `stringify` method to be the culprit here because when I pass a string literal as the ajax data such as `data: {json: "foo"}` it calls my action with no problem whatsoever.

Another weird thing about this is that the response status code isn't 400 everytime. Sometimes there is no status code and the type of the response is "plain". When the response is 400 though, Firebug shows the response as being xml with the message "XML Parsing Error: syntax error Location: moz-nullprincipal:{43263100-2b2a-479c-a38d-d6acac47a39d} Line Number 1, Column 1: Reload the page to get source for: localhost:8080/myAction"
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A lot of that points to problems with the backend, but let's explore your notion that stringify is the problem: what is the result created by stringify? Is it what you expect? Is it what the backend expects?
 
Zahro Alfelpha
Ranch Hand
Posts: 67
1
Spring Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:A lot of that points to problems with the backend, but let's explore your notion that stringify is the problem: what is the result created by stringify? Is it what you expect? Is it what the backend expects?



Stringify produces the expected result when I inspect it at a breakpoint and when printing it to the console. The server just pulls the json string from the request attributes, but it doesn't even get that far, it fails before the first line of server code even executes.

I just discovered that when there is only one entry of "val1": row.find(".val1").text() then it sends to the server just fine. It doesn't matter which one, val1, val2, etc. It Succeeds if there is only one there, but fails if there is more than one. Makes no sense to me

Also, as a sidenote, I am actually calling the text() method in  , forgot to put in in my example code here.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If stringify is returning exactly what you expect, then it can't be the problem. We'll need more information than you are providing here. If the server code is acting erratically (producing different results with the same input) then the problem is clearly there.

Have you inspected the request in the browser debugger to see if there any clues there?
 
Zahro Alfelpha
Ranch Hand
Posts: 67
1
Spring Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:If stringify is returning exactly what you expect, then it can't be the problem. We'll need more information than you are providing here. If the server code is acting erratically (producing different results with the same input) then the problem is clearly there.

Have you inspected the request in the browser debugger to see if there any clues there?



I did look at the request inspector in the browser but didn't find anything I thought was useful.....HOWEVER....I just explicitly set the ajax call to make a POST request.....and it works. I have no idea why, nowhere in my code do I specify that it has to be a post request, and I can access the url just fine by making a GET request manually with the browser.  
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic