问题描述:

I need to request an api from the .dll / .aspx file.

I don't know in what way it is encrypted exactly. I just have the file and the method names . How do i make a request?

When i try to access using ajax method

$.ajax({

type: "POST",

url: "auth.aspx/Login",

data: "{email:'abc', password:'213'}",

contentType: "application/json; charset=utf-8",

dataType: "json",

success: function(msg) {

alert("success: " + msg);

}

});

i got the following error:

XMLHttpRequest cannot load file:///C:/Users/Ganeshk/Desktop/cordova%20app%20crm%20new/ajax/auth.aspx/Login. Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https, chrome-extension-resource.

网友答案:

The error is quite clear; you cannot make an AJAX request to the local file system, in this case your C:/ drive. You need to make the request to a webserver, either local or remote. If you're developing in ASP.Net you can make the request to the local web server instance which Visual Studio spins up when you press F5 to run the site by default.

Also note that the data you're sending is not in the correct format, you should send provide it to the property in an object, like this:

$.ajax({  
    type: "POST",  
    url: "auth.aspx/Login",  
    data: {
        email: 'abc', 
        password: '213' // I assume this will be coming from a user input
    },  
    contentType: "application/json; charset=utf-8",  
    dataType: "json",  
    success: function(msg) {   
        alert("success: " + msg);  
    }
});
相关阅读:
Top