0

Is it possible to use ajax to request a password protected page, pass credentials, and then get the html from the resulting page? I've been playing around with my asp.net mvc application and so far i haven't been able to get it working. here's what my view looks like:

 @Code
  ViewData("Title") = "Index"
 End Code


 <h2>eWeb Job Count</h2>
 <div id="mydiv">
 </div>

<script type="text/javascript">
$(document).ready(function() {
$.ajax({
    type: "POST",
    url: "http://102.143.240.117/dataviews.asp",
    data: "'Administrator', 'password'",
    datatype: "html",
    success: function (dataviewhtml) {
        $('#mydiv').html(dataviewhtml);

    },
    error: function (errorMessage) {
        $('#mydiv').html(errorMessage);
    }

});
});
</script>

when i load the page, i don't get any error messages... just a blank page. is it possible to pass data to a pop up window via ajax? thanks

dot
  • 14,928
  • 41
  • 110
  • 218

1 Answers1

0

Yes, it is possible. jQuery.ajax supports username and password options, you could pass,when requesting:

$.ajax({
    type: "POST",
    url: "http://102.143.240.117/dataviews.asp",
    username : 'Administrator',
    password : 'password',
    datatype: "html",
    success: function (dataviewhtml) {
        $('#mydiv').html(dataviewhtml); 
    },
    error: function (errorMessage) {
        $('#mydiv').html(errorMessage);
    }
});
Engineer
  • 47,849
  • 12
  • 88
  • 91
  • hi. i added those two items but still nothing. No errors either. I tried using the debug tools in IE 9 ... put a break point on the document.ready(). but i'm not getting anything back. I added "console.log(dataiewhtml);" right after i do " $('#mydiv').html(dataviewhtml); " in the successful branch of the ajax call. but it's not displaying anything either. – dot Jun 20 '12 at 19:18
  • i just tried adding some alert statements in the javascript. and it looks like it's going to the error handler of the ajax call. the error message it's showing is [object Object]. any ideas what that is? – dot Jun 20 '12 at 20:21
  • @dot Have you configured your server correctly for permissions? – Engineer Jun 20 '12 at 20:22
  • @dot Are you sure , you want to use HTTP Authentication, that I was thinking of -> http://en.wikipedia.org/wiki/Basic_access_authentication – Engineer Jun 20 '12 at 20:24
  • i changed my error handler to look like: error: function (a, errorMessage, c). And then i include all three variables / parms in my alert statement. The message box is displaying "[object Object]" for the first parameter (XMLHttpRequest I believe),"error" for the message, and "No Transport" for the last parameter - errorThrown. I'm currently reviewing this post to see if it's relevant to my situation: http://stackoverflow.com/questions/5241088/jquery-call-to-webservice-returns-no-transport-error – dot Jun 20 '12 at 20:30
  • can you give me something specific to check with regards to your security comment? thank you, by the way. – dot Jun 20 '12 at 20:40
  • @dot Little question. Are you trying to use `Basic_access_authentication`? – Engineer Jun 20 '12 at 20:43
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/12823/discussion-between-dot-and-engineer) – dot Jun 20 '12 at 20:50