[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

jquery getJSON error

Posted on 2013-11-04
3
Medium Priority
?
559 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 44

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

The most up-to-date version of this article is on my Blog https://iconoun.com/blog/
Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)
Suggested Courses

649 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