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

1 Answer 1

1

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

callbackFunc("aaa");
Sign up to request clarification or add additional context in comments.

5 Comments

Should I for use jsonp always return javascript? Like public string Test2() { return "SomeFunction(aaa);"; }
I used simple javascript (see Edit1) but issue still present
Test2 still invalid. <script> tag added by jquery, you only need alert('Hello world!'); Next thing. You should use this only after document ready.
Thanks, you showed me a solution. But after it strange issue appears (see Edit2)
stackoverflow.com/questions/14255502/…. I didn't knew that, but GET method should accept 'callback' argument and emit code like callback(...).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.