Sto inviando una richiesta di posta a un'applicazione di servizio WCF RESTFUL. Sono in grado di inviare con successo una richiesta POST
tramite Fiddler.jQuery .ajax() Richiesta POST genera 405 (metodo non consentito) su RESTful WCF
Tuttavia quando faccio questo attraverso il metodo di jQuery Ajax la funzione restituisce il seguente al Chrome Console per gli sviluppatori:
OPTIONS http://www.example.com/testservice/service1.svc/GetData 405 (Method Not Allowed) jquery.min.js:6
Ma poi un secondo dopo i registri:
Object {d: "You entered 10"} testpost.html:16
Che cosa questo mi dice è che jQuery sta inviando una richiesta OPTIONS
, che non riesce e quindi invia una richiesta POST
che restituisce i dati previsti.
mio codice jQuery:
$.ajax() {
type: "POST", //GET or POST or PUT or DELETE verb
url: "http://www.example.com/testservice/service1.svc/GetData", // Location of the service
data: '{"value":"10"}', //Data sent to server
contentType:"application/json",
dataType: "json", //Expected data format from server
processdata: false,
success: function (msg) {//On Successfull service call
console.log(msg);
},
error: function (xhr) { console.log(xhr.responseText); } // When Service call fails
});
Sto usando jQuery versione 2.0.2.
Qualsiasi aiuto sul motivo per cui questo errore si sta verificando sarebbe di grande aiuto.
Va bene ha senso ora. Grazie mille. –
would't 'jsonp' fa anche il lavoro - purché sia supportato dal server? – ProblemsOfSumit
@Sumit Se tutto ciò che fai è 'GET', allora ** JSONP ** potrebbe essere un'opzione. Tuttavia, JSONP è più una soluzione alternativa che una soluzione, dal momento che puoi fare cose molto limitate con esso. Non puoi fare 'POST's (o' PUT's ecc.) Tramite JSONP. – acdcjunior