Take the 2-minute tour ×

I have a url which gives json data...

I want to hit that URL from javascript but I am getting this error :


Code :

function a(){

full code :

<html lang="en">

function a(){
<input type="text"/>
<input type="submit" value="search" onclick="a()"/>
share|improve this question
Where does the error appear? –  Quentin Jan 21 '13 at 6:19
In this js : jquery-1.7.1.min.js –  Rishi Jan 21 '13 at 6:19
this is more of a problem with character encoding set by the document interpreting your request. Who controls the server side code for this? –  Brian Vanderbusch Jan 21 '13 at 6:21
which URL do you want to load via AJAX? –  user1386320 Jan 21 '13 at 6:23
@Brian Vanderbusch. Heroku –  Rishi Jan 21 '13 at 6:25

2 Answers 2

up vote 7 down vote accepted

Your code seems correct.

Are you making a fully qualified URL call?

If you are making a fully qualified URL call, make sure of the following.

  1. You are calling the same domain(same server). You can not make a simple JSON call to another domain.
  2. If you want to use a cross domain call, you'll have to use JSONp

Update: This is not working since it is a cross domain call.

Work around for this


Create a function

function getMyData(data) {
    //Do the magic with your data

Server side

On server end wrap your data inside function syntax

getMyData("Enter your data here");


Then create a script tag and add a link to your cross-domain page

 <script type="text/javascript"
         src="cross ref url">

For reference: wikipedia

EDIT: Another option is Create a proxy on your domain. ie create a page in your domain which internally calls the cross-domain page and return the same data to your Ajax call.

share|improve this answer
you mean I must use url as var url=url+"?callback=?" I have used that..I didn't find any result.... –  Rishi Jan 21 '13 at 6:40
No. Can you post the full vale of "url" –  Wolf Jan 21 '13 at 6:44
url="scalajobz.com/getAllJobs?callback=?"; –  Rishi Jan 21 '13 at 6:45
Simply use url = 'getAllJobs' and try –  Wolf Jan 21 '13 at 6:47
Are you calling it from the same domain (ie a page in scalajobz.com itself)? –  Wolf Jan 21 '13 at 6:49

@Wolf: I tried to post the JSON string in myJSONData to the following URL. I am expecting a plain xml from the server. But, I am unable to post the JSON data.

Please see the code snippet I used:

var myJSONData = '{"data":{"mode" : "subscribe","technologyareas":[1],"assettypes":["podcast","documents"]}}';

            type: 'POST',
            url: 'https://tt.s2.acc.com/ttm/subscribe-service/uid=sagar_mate',
            data: myJSONData,
            dataType: 'application/xml',
            success: function(data) { 
          } // Success Function 
          });   // Ajax Call
share|improve this answer
Are you doing it in same domain ??? –  Rishi Jan 22 '13 at 5:57

Your Answer


