?
Solved

jquery getJSON error

Posted on 2013-11-04
3
Medium Priority
?
542 Views
Last Modified: 2013-11-15
I'm running jquery 1.10.2 and this script:

      $.getJSON("http://coldfusion.schupan.com:5001/getprodline?shape=ANG&psc=A&format=json&callback=?", function(json) {
         console.log(json);
      })
     });

This is the json:

{
  "json_list": [
    {
      "descr": "Angle 6061 LBS",
      "prodline": "00A",
      "shape": "ANG",
      "sig": "ALFE"
    },
    {
      "descr": "Angle 6063 LBS",
      "prodline": "00X",
      "shape": "ANG",
      "sig": "ALFE"
    }
  ]
}

I get this error:

"TypeError: this.toArray is not a function"

Why is that?
0
Comment
Question by:kabookis
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 82

Expert Comment

by:leakim971
ID: 39621818
due the callback=? you're using JSONP
jQuery will replace the question mark by a random name
the coldfusion server must return the JSON wrapped by parentheses and in first place, at the beggining put this callback parameter value (the random name)

so you should have something like that at the end of your coldfusion code :

<cfset data = serializeJSON(data)>
<cfif structKeyExists(arguments, "callback")>
     <cfset data = arguments.callback & "(" & data & ")">
</cfif>
<cfreturn data>

Open in new window

0
 
LVL 43

Accepted Solution

by:
Chris Stanyon earned 2000 total points
ID: 39621821
This looks like a cross-domain request, in which case you need to use JSONP, not just JSON. You'd need to use the $.ajax() function for that, and make sure the server is capable of dishing up the correct JSONP format:

$.ajax({
	dataType: "jsonp",
	url: "http://coldfusion.schupan.com:5001/getprodline?shape=ANG&psc=A&format=json",
	success: function(response){
		console.log(response);
	}
});

Open in new window

0
 

Author Closing Comment

by:kabookis
ID: 39652145
OK, I get it now. This script is making a call to a python-generated json URL. In spite of the domain name, there is no CF server involved.
It turned out that all we had to do was install Flask-cors 1.0 in Python, and the request is returned without error as long as the datatype is "json".
The request fails when the datatype is "jsonp".

Sorry for the delay in responding. Thanks for the help.
0

Featured Post

Are You Using the Best Web Development Editor?

The worlds of web hosting and web development are constantly evolving. Every year we see design trends change, coding standards adapt and new frameworks/CMS created. With such a quick pace of change it’s easy to get lost trying to keep up.

See if your editor made the list.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have answered several questions lately that were solved utilizing the power of jQuery's AJAX functions, so I thought I would write an article demonstrating the ease of use. Why should I use jQuery as opposed to regular JavaScript? Now I know…
DOM Attributes and Properties treatment with jQuery 1.6 by Ivo Stoykov jQuery (http://jquery.com/) 1.6 introduces .prop() (http://api.jquery.com/prop/) and .removeProp() (http://api.jquery.com/removeProp/) methods which allow modifying or removi…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses
Course of the Month13 days, 7 hours left to enroll

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question