Click here to Skip to main content
11,930,217 members (39,990 online)
Rate this:
Please Sign up or sign in to vote.
See more: Ajax jQuery
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 1: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 | Mobile
Web04 | 2.8.151126.1 | Last Updated 29 Jan 2013
Copyright © CodeProject, 1999-2015
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