-3

I have backend webService on tomcat server.always when I perform any request (post, get),code enters on error method.

jQuery code is:

var jqxhr = $.ajax(
{
   type:"GET", 
   url:url
   success: function() {    
       alert("success");  
   },
   error: function() {
       alert("fail");
   }    
});

my url is:

http://"192.168.20.220":6060/NostServices/rest/user/resend_activation_email/mailex@blah.com

error message on log is:

XMLHttpRequest cannot load http://"192.168.20.220":8080/NostServices/rest/user/resend_activation_email/dsgg@sdfkmj.com. 
No 'Access-Control-Allow-Origin' header is present on the requested resource. 
Origin 'http://"192.168.20.220":8383' is therefore not allowed access. 

web service server is tomcat.

response of this requset can be 1 for success and -1 for mail not valid

and always enter on fail method and when I try to alert response it output [object object]

thanks you for your help

Simon McLoughlin
  • 8,293
  • 5
  • 32
  • 56
Karim Saad
  • 21
  • 2
  • 8
  • whats the URL your using and print out your error to the console and post here. How else can we diagnose the issue ? – Simon McLoughlin Jan 27 '14 at 09:32
  • http://localhost:8080/NostServices/rest/user/resend_activation_email/mail@yahoo.com – Karim Saad Jan 27 '14 at 09:43
  • no error on consle but I always in fail method. this url must return 1 if success and -1 if valid email – Karim Saad Jan 27 '14 at 09:45
  • Theres no error in the console because your not passing in an object and your not printing it to the console. I asked you to do this and tell me the result. Your question will be closed if you don't edit it and add all these details as its impossible to debug this. AJAX calls using tomcat is a very common thing to do. your doing something wrong, give us all the info! on a side note your using JSONP and your url doesn't specify a callback. I would assume this is related to your issue – Simon McLoughlin Jan 27 '14 at 09:47
  • Thanks Mr.Simon but really I don't know what's problem exactly.If you want to help me you can tell me how to get any data from tomcat server ? – Karim Saad Jan 27 '14 at 11:18
  • ..... your code is failing, error messages tell you why code fails. You need to give us these error messages so we can help you. Your error function has no parameters, add a parameter for the error object. Once you have it, print it to the console. Once its in the console, copy it, once its copied come back to stackoverflow, once your on stackoverflow click edit on this question. Once you've done this add some detail that will give anybody the ability to help you – Simon McLoughlin Jan 27 '14 at 11:23
  • Don't forget to upvote / mark top answer questions that have helped you. If no answer has helped you, leave a comment and add further details. Others facing the same issue will want to know what solved your problem – Simon McLoughlin Feb 03 '14 at 10:28

2 Answers2

0

It's a JSONP request so your server side script needs to return data wrapped in callback:

For example

var url = 'http://example.com/req.json?callback=?';

$.ajax({
   type: 'GET',
   url: url,
   async: false,
   jsonpCallback: 'jsonCallback',
   contentType: "application/json",
   dataType: 'jsonp',
   success: function(json) {
       console.log(json);
   },
   error: function(e) {
       console.log(e.message);
    }
});

And on server side:

jsonCallback({});
waldek_h
  • 930
  • 9
  • 16
0

As your error says your code is failing because of the cross domain error problem. A very detailed answer is found here:

No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin '...' is therefore not allowed access

Please put in some effort to google these issues, this is a very common thing your trying and all errors have been encountered before and have been resolved somewhere. People will get very annoyed here if you show no effort to debug it yourself or provide all the required detail such as:

  • All relevant code
  • Print out of any variables in the code e.g. URL's
  • Any error message
  • A list of things you have tried

On a side note a URL should not have quotes it it. It should not be

http://"192.168.1.1":.........

it should be:

http://192.168.1.1:........

Community
  • 1
  • 1
Simon McLoughlin
  • 8,293
  • 5
  • 32
  • 56