I'm new at AJAX and I'm trying to access a WCF web service the following way:
$(function () {
$('#formNew').submit(function () {
var datos = {
"Nombre": $('#nombre').val(),
"ApellidoP": $('#appP').val(),
"ApellidoM": $('#appM').val(),
"UserName": $('#username').val(),
"Password": $('#password').val(),
};
var args = "Data=" + JSON.stringify(datos);
var url = 'http://127.0.0.1:81/SismosService.svc/usuario/new?' + args;
alert(url);
$.ajax({
type: 'GET',
url: url,
success: function (data) {
alert("Exito " + JSON.stringify(data));
},
error: function (data) {
alert("Error " + JSON.stringify(data));
}
});
});
});
When I fill the form and click the submit button, I get the following error on Firebug:
N
S_ERROR_NOT_AVAILABLE: prompt aborted by user
[Break On This Error]
throw Components.Exception("prompt aborted by user", Cr.NS_ERROR_NOT_AVAILABLE)
My web service is defined as follows:
[WebGet(UriTemplate = "/usuario/new?Data={data}",
RequestFormat = WebMessageFormat.Json,
ResponseFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.Bare)]
ResponseObject<Usuarios> NewUsuario(string data);
What am I doing wrong? Is it the way I'm sending the parameters? Is is the way I'm trying to access the web service? Thanks for any help.
I normally use the following configuration to enable ajax calls to my WCF services:
1) First I create a JSON endpoint behaviour in Web.config and associate my service to it:
2) Then I can simply define my WCF service like this:
3) And finally make jQuery ajax calls like showed below:
The JSON.stringify(data) use is to convert a javascript object to json representation.
I think that in the success\error functions you need to go the other way:
(when using JSON.parse, JSON.stringify - make sure you included the json2.min.js in your project)