Click here to Skip to main content
13,148,573 members (56,606 online)
Rate this:
Please Sign up or sign in to vote.
See more:
why My following jquery function always execute Error block of alert but is available..

<script type="text/javascript">
  $(document).ready(function() {
  function checkIparcel() {
      type: 'GET',
      url: '',
      timeout: 15000,
      success: function(data) { alert('Connected to i-parcel.'); },
      error: function(XMLHttpRequest, textStatus, errorThrown)
      { alert('Error:\r\n' + textStatus); }
</script> site is available.
Still control goes into error block please help..
Posted 29-Jan-13 0:18am
Tadit Dash 29-Jan-13 7:09am
Please check my answer.
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Is your page located on the same domain (i.e. on')?
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).[^][^][^]
mrinal_kumar_jha 29-Jan-13 7:00am
No I am using above code in my local pc.
Vyacheslav Voronenko 29-Jan-13 7:01am
Thus, it will not work due to reasons specified above.
Rate this: bad
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.[^]
Tadit Dash 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 29-Jan-13 7:12am
please share..
mrinal_kumar_jha 29-Jan-13 7:17am
@Tadit Dash : Please share it, or mail me at
Tadit Dash 29-Jan-13 7:28am
Shared - Mrinal_Test_jQuery_Ajax.
Please download and see.
Tadit Dash 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 29-Jan-13 7:46am
I have mailed you also.
mrinal_kumar_jha 30-Jan-13 1:48am
thanks tadit
Tadit Dash 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...

Tadit Dash 30-Jan-13 3:21am
Thanks for accepting the answer @Mrinal.
mrinal_kumar_jha 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 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 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"); }"post", "");
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"); }"post", "");

Tadit Dash 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
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web03 | 2.8.170924.2 | Last Updated 29 Jan 2013
Copyright © CodeProject, 1999-2017
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