0

I need to get data at my application from other domain. I'm tring to use jsonp but every time I have error '80020101'

Here is my code (ASP.NET MVC 4) at 'other domain'

 public ActionResult Test()
 {
    return Json(new { foo = "bar", baz = "Blech" }, JsonRequestBehavior.AllowGet);
 }
 public string Test2()
 {
    return "aaa";
 }

And here is my ajax method what sends a request

$.ajax({
   url: 'https://192.168.0.61/CryptoProTestTool/Home/Test2/',
   type: 'GET',
   dataType: 'jsonp',
   error: function(xhr, status, error) {
      alert("error"); 
   },
   success: function(json) {
      alert("success");
   }
   });

What's wrong? Why do I always have an error in this simple example? I have issue with Test and Test2 data...

Manual testing shows that service sends data enter image description here

EDIT 1: I have an error "Can not finish action. error 80020101." at error function of ajax request. I tried to change Test2 like this

public ActionResult Test2()
{
  return Content("<script language='javascript' type='text/javascript'>alert('Hello world!');</script>"); 
}

But have the same issue

Edit2: Hi again! I was told working solution but after I run it issue appears.

 public ActionResult Test2()
 {
    return Content("MyMethod('test12345');"); 
 }

And Javascript code:

function onPageLoad() {
   CheckCryptoProAvailable();
}

function CheckCryptoProAvailable() {

  $.ajax({
     url: 'https://192.168.0.61/CryptoProTestTool/Home/Test2/',
     type: 'GET',
     dataType: "jsonp",
     error: function(xhr, status, error) {
        alert("error = " + error.toString()); 
     },
     success: function(json) {

     }
  });

}

function MyMethod(testValue){
 alert(testValue);

}

Everything goes ok and MyMethod is called after request. But after it I see a window from ajax request error handler. What's wrong again?

enter image description here

Vitalii
  • 10,091
  • 18
  • 83
  • 151

1 Answers1

1

Where do you get this error? "aaa" is not valid javascript. to use jsonp, you should return something like

callbackFunc("aaa");
  • Should I for use jsonp always return javascript? Like public string Test2() { return "SomeFunction(aaa);"; } – Vitalii Mar 18 '13 at 20:32
  • I used simple javascript (see Edit1) but issue still present – Vitalii Mar 19 '13 at 06:27
  • Test2 still invalid. – user2183861 Mar 19 '13 at 07:42
  • Thanks, you showed me a solution. But after it strange issue appears (see Edit2) – Vitalii Mar 19 '13 at 17:32
  • http://stackoverflow.com/questions/14255502/error-jquery-was-not-called. I didn't knew that, but GET method should accept 'callback' argument and emit code like callback(...). – user2183861 Mar 21 '13 at 11:01