Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Ajax jQuery
why My following jquery function always execute Error block of alert but js.i-parcel.com is available..
 
------------------------
<script type="text/javascript">
  $(document).ready(function() {
  });
  function checkIparcel() {
    $.ajax({
      type: 'GET',
      url: 'https://js.i-parcel.com',
      timeout: 15000,
      success: function(data) { alert('Connected to i-parcel.'); },
      error: function(XMLHttpRequest, textStatus, errorThrown)
      { alert('Error:\r\n' + textStatus); }
    });
  }
</script>
 
https://js.i-parcel.com site is available.
Still control goes into error block please help..
Posted 29-Jan-13 1:18am
v2
Comments
Tadit Dash at 29-Jan-13 7:09am
   
Please check my answer.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Is your page located on the same domain (i.e. on https://js.i-parcel.com')?
If not, you can't just directly access it with $.ajax due to cross domain restrictions. (If there is an REST API, you might want to use JSONP, or perhaps use CORS for moderm browsers).
 
http://en.wikipedia.org/wiki/Same_origin_policy[^]
 
http://en.wikipedia.org/wiki/JSONP[^]
 
http://en.wikipedia.org/wiki/Cross-origin_resource_sharing[^]
  Permalink  
Comments
mrinal_kumar_jha at 29-Jan-13 7:00am
   
No I am using above code in my local pc.
Vyacheslav Voronenko at 29-Jan-13 7:01am
   
Thus, it will not work due to reasons specified above.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

I tested this and it is working fine.
Going to success and giving alert 'Connected to i-parcel.'.
 
Check Live Demo.[^]
Comments
Tadit Dash at 29-Jan-13 7:09am
   
Update - It is also working on my local. If you need, then I can share you the file to download.
mrinal_kumar_jha at 29-Jan-13 7:12am
   
please share..
mrinal_kumar_jha at 29-Jan-13 7:17am
   
@Tadit Dash : Please share it, or mail me at mrinalkumarjha@ymail.com
Tadit Dash at 29-Jan-13 7:28am
   
Shared - Mrinal_Test_jQuery_Ajax.
Please download and see.
Tadit Dash at 29-Jan-13 7:32am
   
May be your connection is taking time to connect.
So, try to increase the timeout value above 15000.
Tadit Dash at 29-Jan-13 7:46am
   
I have mailed you also.
mrinal_kumar_jha at 30-Jan-13 1:48am
   
thanks tadit
Tadit Dash at 30-Jan-13 1:57am
   
You are most welcome. Anytime. My pleasure.
 
Please accept this answer, if it has helped you in any way.
This will help others to find the answer in one go and you will also be awarded with some points for this action...
 
Thanks,
Tadit
Tadit Dash at 30-Jan-13 3:21am
   
Thanks for accepting the answer @Mrinal.
mrinal_kumar_jha at 30-Jan-13 3:27am
   
No need to say thanks tadit You guys are really doing well job here.. It helps newbbies lot.. :)
Tadit Dash at 30-Jan-13 5:09am
   
Thanks for your compliments @Mrinal.
 
I will try to help everyone here, as far as I can.
And I feel so satisfied, when somebody solves his/her issue due to my suggestions. It really feels great.
mrinal_kumar_jha at 13-Mar-13 4:49am
   
This is the solution for all CORS supported browser.
<script type="text/javascript">
//IE support CORS through XDomainRequest
var browserName = navigator.appName;
if (browserName == "Microsoft Internet Explorer") {
 
var xdr;
xdr = new XDomainRequest();
alert("Connecting to i-Parcel Cloud...");
if (xdr) {
xdr.onerror = function () { alert("Error"); }
xdr.ontimeout = function () { alert("Timeout"); }
xdr.onload = function () { alert("Connected to i-Parcel"); }
xdr.open("post", "http://checkout.i-parcel.com/rest/isc/track");
xdr.send();
}
}
else {
////Other browser support CORS through XMLHttpRequest
var xhr;
xhr = new XMLHttpRequest();
alert("Connecting to i-Parcel Cloud...!!");
xhr.onerror = function () { alert("Error"); }
xhr.ontimeout = function () { alert("Timeout"); }
xhr.onload = function () { alert("Connected to i-Parcel"); }
xhr.open("post", "http://checkout.i-parcel.com/rest/isc/track");
xhr.send();
}
 
</script>
Tadit Dash at 13-Mar-13 7:30am
   
Ok. Great... Welldone.

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 345
1 OriginalGriff 210
2 DamithSL 210
3 Kornfeld Eliyahu Peter 210
4 Peter Leow 95
0 OriginalGriff 7,215
1 DamithSL 5,199
2 Maciej Los 4,866
3 Sergey Alexandrovich Kryukov 4,757
4 Kornfeld Eliyahu Peter 4,514


Advertise | Privacy | Mobile
Web03 | 2.8.141223.1 | Last Updated 29 Jan 2013
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