3

I have an application that's been provided by a third party. The only means of modifying the behavior is through client side script. I have a screen in the app that does some ad-hoc querying but doesn't provide any means by which to save the settings. Rather than have the user re-enter setting each time, I've injected some elements via jQuery to enable them to save their queries.

I have another internal site that is asp.net MVC that I've added a controller with a method GetQueryList(string User).

From the browser everything work fine, I get my result returned, but from script I get a 403. I've been chasing my tale for two days on this now.

I dumbed down the methods to just get things working.

Here's the controller code:

<AcceptVerbs(HttpVerbs.Get)> _ 
Public Function GetQueryList(ByVal user as String) as JsonResult   
    Return Me.Json(String.format("Hello {0}", user))
End Function

Client code:

    $.getJSON("http://myservername.org/ClientQuery.mvc/GetQueryList",
        null
        , function (data) {
            alert(data);
        }
    );

If anyone has any ideas it might save what little hair I have left.

DaveRandom
  • 87,921
  • 11
  • 154
  • 174
Bert Smith
  • 701
  • 3
  • 11

1 Answers1

0

You get that error because browsers implement a Same Origin Policy that blocks AJAX requests to other domains.

You can create a local AJAX class to proxy the external AJAX request on behalf of the user, using a .NET WebRequest. Note that WebRequest has no constructor and uses a factory method WebRequest.create(Uri) instead.

Powerlord
  • 87,612
  • 17
  • 125
  • 175
  • This is what I feared. Question becomes now how to implement the proxy when I don't have access to the the application code? Again the only modifications I'm able to make in the applications are client side behavoirs via javascript. – Bert Smith Dec 03 '09 at 16:25
  • You get the the check because I believe you answered the question I had initially which was why. Your answer confirmed my suspicion and eventually led me to the as described here. http://stackoverflow.com/questions/758879/asp-net-mvc-returning-jsonp – Bert Smith Dec 03 '09 at 20:23
  • I feel stupid now. I didn't even think of JSONP, which is JSON with a Javascript callback on the caller, that nicely averts the need for a proxy. – Powerlord Dec 03 '09 at 20:55