[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

jquery getJSON error

Posted on 2013-11-04
3
Medium Priority
?
574 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
3 Comments
 
LVL 83

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 45

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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

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 most up-to-date version of this article is on my Blog https://iconoun.com/blog/
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 Month17 days, 18 hours left to enroll

831 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