0

嘿,伙计们,我在使用 ajax PUT 时遇到了一个愚蠢的问题,在我尝试将 json 数据放回之后,即使我使用了:dataType:“application/json”,服务器也会认为它的 xml 数据,知道为什么会发生这种情况吗?这就是我的 PUT 的样子:

$.ajax({ 
type: "PUT", 
url: bank_url, 
dataType: "application/json", 
data: {"banking_detail_id": page.viewModel.payer_banking_detail_id(),
 "person_id": person_id, "account_number": page.viewModel.payer_account_number(),
 "branch": page.viewModel.payer_branch(), "date_inserted": page.viewModel.payer_date_insterted(),
 "date_effective": page.viewModel.payer_date_effective(), "account_type": page.viewModel.payer_account_type(),
 "account_holder": page.viewModel.payer_account_holder() , "debit_day": page.viewModel.payer_debit_day() ,
 "branch_code": page.viewModel.payer_branch_code() , "bank_branch_id": page.viewModel.payer_bank_branch_id(),
 "branch_name": page.viewModel.payer_branch_name(), "bank_name": page.viewModel.payer_bank_name(),
 "user_id": page.viewModel.payer_user_id()}, 
}); 

服务器响应如下:

xhr = {"length":847,"name":"error","severity":"ERROR","code":"23502","detail":"失败行包含 (null, 1081563, 12341234, ABSA ELECTRONIC结算 CNT (632005), 2013-05-05 00:00:00, 2013-05-06, 0, Coetzee MA, 1, null, 0)。","where":"SQL 语句 \"INSERT INTO bank_detail( \n\t\t\t\tbanking_detail_id,\n\t\t\t\tperson_id,\n\t\t\t\taccount_number,\n\t\t\t\tbranch,\n\t\t \t\tdate_inserted,\n\t\t\t\tdate_effective,\n\t\t\t\taccount_type,\n\t\t\t\taccount_holder,\n\t\t\t\tdebit_day,\ n\t\t\t\tbank_branch_id, \n\t\t\t\tuser_id)\n\t\t\tVALUES (\n\t\t\t\tnew.banking_detail_id,\n\t\t\ t\tnew.person_id,\n\t\t\t\tnew.account_number,\n\t\t\t\tnew.branch,\n\t\t\t\tnew.date_inserted,\n\t\ t\t\tnew.date_effective,\n\t\t\t\tnew.account_type,\n\t\t\t\tnew.account_holder,\n\t\t\t\tnew.debit_day,\n\t\t\t\tnew. bank_branch_id,\n\t\t\t\tnew.user_id)\"\nPL/pgSQL function bank_detail_view_set() 第 4 行 SQL 语句","file":"execMain.c","line":"1527", “例程”:“执行约束”}

4

1 回答 1

1

请求类型是 GET 或 POST ex:

    type: "GET", 
    type: "POST", 

dataType 是 xml、json、script 或 html,例如:

    dataType:'html',
    dataType:'xml',
    dataType:'json',
    dataType:'script',
于 2013-05-07T12:24:35.403 回答