Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Javascript JSONP
Hello guys ,
Stuck at a problem for two days . The problem is that i am trying to hit a webservice from localhost .
Just for testing purposes i wrote this code and it ran the way it was supposed to :
<a href="http://www.zipdial.com/z2v/startTransaction.action?customerToken=mycustomertoken&clientTransactionId=1&callerid=9968280904&duration=180&countryCode=91&z2vToken=another_token">Save</a>
As you can see , everything is static and it works like a charm because i see something like this on the browser :
{"message":"ok","client_transaction_id":"2","transaction_token":"sometoken","status":"1","img":"http://www.zipdial.com/zip2auth/images/access/b8b7ad5781c6f07b775f623ab62f4f8d34f81570"}
Now i need to extract the img element from it but i have no idea in how to go about it .
I tried using jquery like this :
$(document).ready(function() {
     
		 alert('hello');
 
		 $.getJSON("http://www.zipdial.com/z2v/startTransaction.action?customerToken=mycustomertoken&clientTransactionId=2&callerid=9968280904&duration=180&countryCode=91&z2vToken=another_token",function(jd)
		{
			alert("hello again");
             alert(jd.image);
             
          });
	});
Now i only see the alert("hello") as a pop up but nothing inside the function call and on my browser i see this
"Origin http://server_name is not allowed by Access-Control-Allow-Origin."
Please help
Posted 27-Oct-12 6:39am
Edited 27-Oct-12 9:16am
v2

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

As I see, this is a cross-domain call. Thus a simple getJSON won't be enough. Consult the legacy ajax[^] method to see how you have to set parameters for a JSONP call.
  Permalink  
Comments
Member 9459463 at 27-Oct-12 13:08pm
   
Zoltan , i read the jsonp a bit ( i forgot to mention i am fairly new ) but according to that the server side code which i need to call should have a function which i could call . If that is the case then i cannot call the function as i can't change the code at that side . Am i right ?
Zoltán Zörgő at 27-Oct-12 13:15pm
   
Not absolutely necessary, forget JSONP for a second, and try it as a regular json call, but with CrossDomain settings. Shoul work.
Member 9459463 at 27-Oct-12 13:19pm
   
How do i do that ?
Zoltán Zörgő at 27-Oct-12 15:46pm
   
http://james.padolsey.com/javascript/cross-domain-requests-with-jquery/

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 277
1 Maciej Los 240
2 DamithSL 200
3 Raul Iloc 185
4 Richard MacCutchan 175
0 OriginalGriff 5,130
1 DamithSL 4,197
2 Maciej Los 3,670
3 Kornfeld Eliyahu Peter 3,470
4 Sergey Alexandrovich Kryukov 2,821


Advertise | Privacy | Mobile
Web01 | 2.8.141216.1 | Last Updated 27 Oct 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100