Click here to Skip to main content
15,887,214 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i am new to C# , and i created a sample website which will use a REST Service for login , for that i am calling the service by ajax call in j query , so i have two problems , one is the ajax call is not at all hitting the service and another is the code which i wrote for page relocation (window.location.href="sample";) is not working , the code is as fallows .

What I have tried:

$(document).ready(function () {

debugger;


$("#ContentPlaceHolder1_btnSubmit").click(function () {
debugger;
var obj = new Object();
obj.UserID = $('#ContentPlaceHolder1_txtUserid').val();
obj.Password = $('#ContentPlaceHolder1_txtPassword').val();

debugger;

$.ajax({
type: 'POST',
url: "http://192.168.124.69:447/api/AFSService/checkLogin/",
//headers: {
// "$Access-Control-Allow-Headers": "X-Requested-With"
//},
crossDomain: false,
data: obj,
async: false,
contentType: "application/json; charset=utf-8",
dataType: 'json',
success: function (result) {
debugger;
alert('success');
debugger;

window.location.replace = "http://localhost:50990/Jobs.aspx";

//return Json(new { Url : "http://localhost:50990/Jobs.aspx"})

//$json['redirect'] = "http://localhost:50990/Jobs.aspx";

//window.navigate("http://localhost:50990/Jobs.aspx")

//window.location.href="http://localhost:50990/Jobs.aspx";

// top.location.href= "D:\Home.html";
},

error: function (data) {
debugger;

alert('enter the proper credentials');

debugger;
//window.location.href = "http://localhost:50990/Jobs.aspx";
window.location.href = "http://localhost:50990/Jobs.aspx";

}

});
});

});
Posted
Comments
F-ES Sitecore 18-Dec-17 11:39am    
Use the network tools of the browser to see if you can get more info about what is going on

https://forums.asp.net/t/1982579.aspx?Using+the+browser+s+dev+tools+to+diagnose+ajax+problems+and+other+things+
VamsiMadugula 18-Dec-17 12:22pm    
Thanks for the suggestion , i tried this , and i debugged it by using browser debugging , it was reaching up to the ajax call , and then directly jumping into the error message . , and the code which i wrote and the code of the service are in same language , so no need to use of CORS , i am not understanding what is happening , and it was showing 404 error and i checked the link in SOAP and it is working
Richard Deeming 18-Dec-17 12:50pm    
The language you used is irrelevant. If the page that's running and the service it's trying to call are on different origins, then you need CORS headers on the server.

localhost:50990 and 192.168.124.69:447 are different origins. Therefore, you need CORS headers on 192.168.124.69:447.
VamsiMadugula 19-Dec-17 5:06am    
As per your suggestion i used url:"http://cors.io/?http://192.168.124.69:447/api/AFSService/checkLogin/", instead of //url: "http://192.168.124.69:447/api/AFSService/checkLogin/", and i got an error like this
jquery-1.10.2.min.js:23 OPTIONS http://cors.io/?http://192.168.124.69:447/api/AFSService/checkLogin/ 403 (Forbidden)
and i tried the following code https://crossorigin.me/http://192.168.124.69:447/api/AFSService/checkLogin/ and the error message is https://crossorigin.me/http://192.168.124.69:447/api/AFSService/checkLogin/ net::ERR_CONNECTION_CLOSED
Richard Deeming 19-Dec-17 7:55am    
Firstly, it should probably be https://cors.io/..., not http://... - the site should redirect the request to HTTPS, but it's better to make the initial request secure in the first place.

Secondly, if you're trying to make a cross-origin request using the current user's authentication details, you cannot use a proxy like this. Your have to make the request directly, which means getting the author of the service you're calling to add the correct CORS headers.

If they won't add the CORS headers, then you are not allowed to do what you're trying to do.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900