Click here to Skip to main content
15,881,380 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
why My following jquery function always execute Error block of alert but js.i-parcel.com is available..

------------------------
XML
<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
v2
Comments
Please check my answer.

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[^]
 
Share this answer
 
Comments
k@ran 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.
I tested this and it is working fine.
Going to success and giving alert 'Connected to i-parcel.'.

Check Live Demo.[^]
 
Share this answer
 
Comments
Update - It is also working on my local. If you need, then I can share you the file to download.
k@ran 29-Jan-13 7:12am    
please share..
k@ran 29-Jan-13 7:17am    
@Tadit Dash : Please share it, or mail me at mrinalkumarjha@ymail.com
Shared - Mrinal_Test_jQuery_Ajax.
Please download and see.
May be your connection is taking time to connect.
So, try to increase the timeout value above 15000.

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900