0

When jquery is running this is not going "success" this is going in "error" section.My php file is on another server.code is like below.

  $(document).ready(function() {  

    //if submit button is clicked  
    $('#recaptcha_reload').click(function () { 
   var data ="publick="+document.getElementById("publickeyval").value+"&privatek="+document.getElementById("privatekeyval").value;

 alert(data);
//start the ajax  
      $.ajax({

           //this is the php file that processes the data and send mail  
           url: "http://www.example.com/example_api/example_adcpatchaapi.php",   

           //GET method is used  
           type: "GET",  

           //pass the data           
           data: data,       

           //Do not cache the page  
           cache: false,  

           //success  
           success: function (html) { 
alert(html);

               if (html) {      

document.getElementById('captcha_table').innerHTML=html;    


               }    else{
      alert("####");  // runing this alert box
 }
           },
    error : function(XMLHttpRequest, textStatus, errorThrown) {
            alert(XMLHttpRequest.status); // showing 0 
        }      
       });  

       //cancel the submit button default behaviours  
       return false;  
   });   

});

ACP
  • 34,682
  • 100
  • 231
  • 371
Ajay_kumar
  • 21
  • 4
  • I am accessing my php file "example_adcpatchaapi.php" remotely.This javascrpt is running on another server. – Ajay_kumar Sep 14 '10 at 06:15

2 Answers2

1

Sorry to say, same origin policy applies, you cant access pages outside the current domain/server using AJAX

Kristoffer Sall-Storgaard
  • 10,576
  • 5
  • 36
  • 46
  • How will i overcome this problem ? Is it restricted by my hosting plan ? – Ajay_kumar Sep 14 '10 at 06:26
  • 1
    Unfortunately no, its restricted by your PHP script being hosted on a different server than your javascript/jquery, if you really want to do it on another server you will have to look into JSONP: http://stackoverflow.com/questions/2067472/please-explain-jsonp – Kristoffer Sall-Storgaard Sep 14 '10 at 06:30
0

Use JSONP for cross-site callbacks.

Some useful links:

Naveed
  • 41,517
  • 32
  • 98
  • 131