Click here to Skip to main content
15,567,466 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 () {


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


type: 'POST',
url: "",
//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) {

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

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

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



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

error: function (data) {

alert('enter the proper credentials');

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



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
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 are different origins. Therefore, you need CORS headers on
VamsiMadugula 19-Dec-17 5:06am    
As per your suggestion i used url:"", instead of //url: "", and i got an error like this
jquery-1.10.2.min.js:23 OPTIONS 403 (Forbidden)
and i tried the following code and the error message is net::ERR_CONNECTION_CLOSED
Richard Deeming 19-Dec-17 7:55am    
Firstly, it should probably be, 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