簡體   English   中英

錯誤400方法POST

[英]error 400 method POST

每次我運行ajax jquery函數時,都會出現錯誤400

這是我的代碼,郵遞員測試都是肯定的,但是當webapp運行程序運行時,它不起作用,我不知道這是否取決於代碼或html5有人可以幫助我嗎?

JavaScript的

function add() {

var url= "http://localhost:8080/bip/workAdd";

var work = {
    codiceCommessa: document.getElementById("codiceCommessa").value,
    commessaMainSub: document.getElementById("commessaMainSub").value,
    settoreCliente: document.getElementById("settoreCliente").value,
    nomeCliente: document.getElementById("nomeCliente").value,
    clienteFinale: document.getElementById("clienteFinale").value,
    titoloQuals: document.getElementById("titoloQuals").value,
    keyWorrdsTopic: document.getElementById("keyWordsTopic").value,
    keyWordsActivities: document.getElementById("keyWordsActivities").value,
    anno: parseInt(document.getElementById("anno").value),
    dataInizio: document.getElementById("dataIniziale").value,
    dataFine: document.getElementById("dataFinale").value,
    referente: document.getElementById("referente").value,
    referenteDocumentazione: document.getElementById("referenteDocumentazione").value,
    sviluppatore: document.getElementById("sviluppatore").value,
    path: document.getElementById("path").value


};



$.ajax({

    contentType: "application/json; charset=utf-8",
    'Access-Control-Allow-Headers': '*',
    'Access-Control-Allow-Origin': '*',
    'Access-Control-Allow-Methods': 'POST',

    type: "POST",
    url: url,
    data: work,

    dataType: "html or json",
    success: function (data, status, jqXHR) {
        console.log("saved"),

    },

    error: function (jqXHR, status) {

                    console.log("error")


    }

});
function add() {

var url= "http://localhost:8080/bip/workAdd";

var work = {
    codiceCommessa: document.getElementById("codiceCommessa").value,
    commessaMainSub: document.getElementById("commessaMainSub").value,
    settoreCliente: document.getElementById("settoreCliente").value,
    nomeCliente: document.getElementById("nomeCliente").value,
    clienteFinale: document.getElementById("clienteFinale").value,
    titoloQuals: document.getElementById("titoloQuals").value,
    keyWorrdsTopic: document.getElementById("keyWordsTopic").value,
    keyWordsActivities: document.getElementById("keyWordsActivities").value,
    anno: parseInt(document.getElementById("anno").value),
    dataInizio: document.getElementById("dataIniziale").value,
    dataFine: document.getElementById("dataFinale").value,
    referente: document.getElementById("referente").value,
    referenteDocumentazione: document.getElementById("referenteDocumentazione").value,
    sviluppatore: document.getElementById("sviluppatore").value,
    path: document.getElementById("path").value


};



$.ajax({

    contentType: "application/json; charset=utf-8",
    'Access-Control-Allow-Headers': '*',
    'Access-Control-Allow-Origin': '*',
    'Access-Control-Allow-Methods': 'POST',

    type: "POST",
    url: url,
    data: JSON.stringify(work),

    dataType: "html or json",
    success: function (data, status, jqXHR) {
        console.log("saved"),

    },

    error: function (jqXHR, status) {

                    console.log("error")


    }

});

您需要使用JSON.stringify(work)

這部分都搞砸了:

contentType: "application/json; charset=utf-8",
'Access-Control-Allow-Headers': '*',
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'POST',

contentType行是正確的,但是您需要將其他選項包裝在headers: { ..... },

服務器可能無法識別數據 您可能需要對JSON進行字符串化。

您嘗試傳遞給Ajax函數的工作詞典應該類似於work = {'a':'b','c':'d'}但是,就像您的情況一樣,它是: work = {a:'b', c:'d'}因此,在將其傳遞給ajax之前,請使用JSON.stringify方法如上所述更改該數據的格式。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM