• 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

Problem with getJSON in JQuery

 
Ranch Hand
Posts: 502
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My HTML is

When I click on the button I get the first alert, but I don't get the second alert. http://localhost:8080/rest/state/person/name displays; {"name":"handro","age":"67"} which is correct JSON. I don't understand why is the call back is not being used.
 
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
alerts screw up everything that they touch because they block on execution. Before even looking at the code, please replace the alerts with either console.log logging -- which will not block execution -- and also learn about using breakpoints to debug.

Post back if you still see odd behavior when the alerts are gone.
 
Alejandro Barrero
Ranch Hand
Posts: 502
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you very much for your reply. I changed my code to

When clicking on the button I get an error in the console:
randomPerson JQuery.html:22
XMLHttpRequest cannot load http://localhost:8080/rest/state/person/name. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access. JQuery.html

I could not get the log, but now I see there is a problem. Could you tell me how to solve this problem.
 
Alejandro Barrero
Ranch Hand
Posts: 502
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Now I see that I am using a different domain.
 
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
It thinks that you are trying to make a cross-site request without CORS, and that of course can never work.

If you are making a request to the same server you should never include the domain. So your URL should be '/rest/state/person/name' without the redundant prefix.

If you actually are trying to make a cross-domain request, the server will need to support CORS.
 
Are we home yet? Wait, did we forget the tiny ad?
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic