http://localhost:57501/api/addDatabase web hizmeti aşağıdaki koda sahiptir.jQuery gönderimi ile boş Web hizmeti alımı JSON
[System.Web.Mvc.HttpPost]
public ActionResult Post(addDatabase pNuevaConeccion)
{
pNuevaConeccion.insertarMetaData();
return null;
}
Ajax fonksiyonu http://localhost:1161/CreateServer üzerinde vermek değerlerinden JSON yaratan bir javascript üzerindedir.
$ (belge) .ready (fonksiyonu() {
$("#createServer").click(function (e) {
e.preventDefault(); //Prevent the normal submission action
var frm = $("#CreateServerID");
var dataa = JSON.stringify(frm.serializeJSON());
console.log(dataa);
$.ajax({
type: 'POST',
url: 'http://localhost:57501/api/addDatabase/',
contentType: 'application/json; charset=utf-8',
crossDomain: true,
//ContentLength: dataa.length,
data: dataa,
datatype: 'json',
error: function (response)
{
alert(response.responseText);
},
success: function (response)
{
alert(response);
if (response == "Database successfully connected") {
var pagina = "/CreateServer"
location.href = pagina
}
}
});
});
}); Bu kodu çalıştırdığımda "undefined" ("undefined") belirten bir uyarı açılır, ancak contentType öğesini silersem uyarı görünmez. Sorun, Post (Web hizmetinden) işlevinin aldığı değişkenlerin, bir konsol.log yaptığımdan beri JSON adlı DataA'nın NULL olmadığını bilmeme rağmen NULL olduğu.
Çeşitli örnekler gördüm ve hemen hemen hepsi göreli bir URL kullanmam gerektiğini söylüyor ama sorun şu ki 2 farklı etki alanı bulunduğundan ve denediğimde URL’yi bulamadı çünkü URL’yi bulamadı aynı localhost'ta.