0
jQuery.support.cors = true;
    var URL = 'http://blahblah:5555/blahblahWS';
    $.ajax({
        type: 'POST',
        url: URL,
        dataType: 'html',
        success: function( data, status ){
            alert( data.responseData.results.length + ' results found!' );
            $('#curr').wrapInner('<span class="icon green">q</span>');
        },
        error: function() {
            $('#curr').wrapInner('<span class="icon red">r</span>');
        }
    });

FYI, jQuery.support.cors = true; is required to call localservices, type is POST compulsory,

I like to show green or red icon based on the response of webservice called, it always gives me error, donno why

but when i tried through this

jQuery.support.cors = true;
$("#success").load("http://blahblah:5555/blahblahWS", function(response, status, xhr) {
  if (status == "error") {
    var msg = "Sorry but there was an error: ";
    $("#error").html(msg + xhr.status + " " + xhr.statusText);
  }
  if (status == "success") {
        var msg = "no error ";
        $("#success").html(msg + xhr.status + " " + xhr.statusText);
      }
});

It shows 200 OK response

saying Hello! This is an Axis2 Web Service!

What's the difference and how can i correct it in #.ajax()?

cypronmaya
  • 520
  • 1
  • 11
  • 24
  • Do you have access to the logs on blahblah? Can you confirm the request is actually getting there? – malonso Feb 12 '12 at 15:06
  • whats the error message in the former case? – supertopi Feb 12 '12 at 15:07
  • It shows 200 OK response saying Hello! This is an Axis2 Web Service! – cypronmaya Feb 12 '12 at 15:09
  • You have replaced POST with GET to get it working, so there could be a problem with processing POST requests. – Stan Feb 12 '12 at 15:11
  • what's your server-side code? –  Feb 12 '12 at 15:13
  • @supertopi it shows undefined as message and error as status – cypronmaya Feb 12 '12 at 15:20
  • @Stan if i use GET it wouldn't even get atleast error response – cypronmaya Feb 12 '12 at 15:21
  • @allentranks i donno wht server-side code is, let's just say i have service URl and when i opened it in browser it shows me Hello! This is an Axis2 Web Service!, in the sameway how can i get status using ajax call :) – cypronmaya Feb 12 '12 at 15:24
  • I don't understand. You wrote that you open this URI in browser successfully, so it definitely can work with GETs. – Stan Feb 12 '12 at 15:43
  • Ya its true, but when i use GET instead of post i can see that it neither goes to success: nor error: , so i 've used POST , where atleast it goes to error: saying Bad Request. – cypronmaya Feb 12 '12 at 15:47

1 Answers1

1

try this link for the learn how to call cross domain ajax request

http://cmsnsoftware.blogspot.com/2012/02/how-to-use-cross-domain-ajax-request.html

see my answer for this question.

$.ajax call working fine in IE8 and Doesn't work in firefox and chrome browsers

if you don't have access to your webservice, you can create proxy webservice in your server side. call the web service in serverside and then respone to client side. that response can read as normal webservice.

Community
  • 1
  • 1
Chamika Sandamal
  • 23,565
  • 5
  • 63
  • 86
  • as u said it's working fine in IE8,FYI i couldn't even see that and i can't edit the webservice to my purposes – cypronmaya Feb 12 '12 at 17:34
  • try the way in [above link](http://cmsnsoftware.blogspot.com/2012/02/how-to-use-cross-domain-ajax-request.html) to access cross domain web services. – Chamika Sandamal Feb 12 '12 at 17:36