Why my gadget is not receiving data?

363 views Asked by At

I have my application on appspot. This is on personal domain account.

I have put an iGoogle Gadget on iGoogle Page of my gmail account.

I am sending ajax request from my gadget like :

          $(document).ready(function(){
                jQuery.ajax({
                    type: "get",
                    url: "http://searcegadget2.appspot.com/requestServlet",
                    success: function(msg){
                        alert(msg);
                        if(msg.search('tr') != -1){
                            id = msg.split('</tr>').length - 1;
                            //alert(id);
                            $('#amountTable').append(msg);
                            difference();
                        }else if(msg.search('form') != -1){
                            $('#gadget').css('display', 'none');
                            document.write(msg);
                        }else if(msg.search('http') != -1){
                            document.location = msg;
                            $('#amountTable').append(msg);
                        }

                    },error: function(XMLHttpRequest, textStatus, errorThrown){
                        alert("XMLHttpRequest: " + XMLHttpRequest.responseText);
                        alert("textStatus : " + textStatus.responseText);
                        alert("errorThrown : "+ errorThrown);
                    }
                });
            });

There is nothing shown in XMLHttpRequest & errorThrown alerts. But, there is "error" shown in textStatus !

Now, the link "http://searcegadget2.appspot.com/requestServlet" is shown in red and when I open the "http://searcegadget2.appspot.com/requestServlet" from Inspect Element in Mozilla, it returns me the required data as well ! How do I attach it to my gadget ?

My request servlet is in java. For reference : jQuery.ajax()

Also, I have tested this web application. That is working properly !

1

There are 1 answers

0
dplouffe On

Without seeing an error message or and error code it's hard to tell what your issue is, but from your post, I would think that it's a cross-domain scripting issue. You can't do an XMLHttpRequest from a different domain. (e.g. gmail.com cannot do an XMLHttpRequest to searcegadget2.appspot.com without throwing an error).

Try add the Access-Control-Allow-Origin header to the response of the controller which handles your requestServlet endpoint.

For more information of the Access-Control-Allow-Origin header, see this thread:

Access-Control-Allow-Origin Multiple Origin Domains?