ajax没有';我不能使用php
我一直在尝试使用ajax将数据插入数据库,但没有成功。因此,我编写了一段代码,尝试对php文件进行基本调用,但也没有成功: 以下是我的html代码:ajax没有';我不能使用php,php,jquery,html,ajax,Php,Jquery,Html,Ajax,我一直在尝试使用ajax将数据插入数据库,但没有成功。因此,我编写了一段代码,尝试对php文件进行基本调用,但也没有成功: 以下是我的html代码: <form > <h4 class="header-title m-t-0 m-b-30">Cordonnées de facturation</h4> <div class="form-group"> <label class="col-md-4 contr
<form >
<h4 class="header-title m-t-0 m-b-30">Cordonnées de facturation</h4>
<div class="form-group">
<label class="col-md-4 control-label">code facture</label>
<div class="col-md-6">
<input type="text" id="code_facture" class="code_facture form-control" placeholder="Ex : 008A00098">
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">Numéro du dossier</label>
<div class="col-md-6">
<input type="text" id="code_dossier" class="code_dossier form-control" placeholder="Ex : 008A00098">
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">TPS</label>
<div class="col-md-6">
<input type="text" id="tps" class="tps form-control" placeholder="Ex : 0">
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">TVQ</label>
<div class="col-md-6">
<input type="text" id="tvq" class="tvq form-control" placeholder="Ex : 0">
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">Référence</label>
<div class="col-md-6">
<input type="text" id="reference" class="reference form-control" placeholder="Ex : VAR R4055555">
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">PNR</label>
<div class="col-md-6">
<input type="text" id="pnr" class="pnr form-control" placeholder="Ex : M15478LD265">
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">Date de facturation</label>
<div class="col-md-6">
<input type="text" placeholder="12/12/2012" data-mask="99/99/9999" id="date_facturation" class="date_facturation form-control">
<span class="font-13 text-muted">jj/mm/aaaa</span>
</div>
</div>
<div class="form-group">
<button type="submit" class="btn" id="addfacturebutton"> ajouter</button>
</div>
您的代码无法确认js代码是否有效 试试这个: 更改此行:
success:function(data){
}
致:
并更改以下情况的每次发生:
').val()
到
如果有警报,那么js正在工作。在您的php代码中,我看不到任何与数据库相关的内容。您是否尝试转储
insertFacture.php
文件的$\u POST
?似乎您的php文件名或函数确实有问题。php
要减少ajax中的代码行,您可以在表单标记上添加一个id属性,然后序列化()
或使用FormData()
input[id=code\u facture
冗余且不正确ajax代码的字符串语法中存在太多问题(没有关闭括号[this]
)由于回调中没有发生任何事情,您无法判断某个操作是否有效。ajax调用中有太多打字错误。而且成功函数也没有任何作用。您的代码似乎很好。您的数据库查询在哪里?检查ajax是否起作用。打开控制台。转到“网络”选项卡。然后提交请求。在那里,您可以看到什么是数据发布和什么回复来了。这应该在评论部分。我没有足够的声誉:(@MZaragoza你显然是指$\u POST
[使用反勾(`)而不是单引号(')]在我的手机上很难做到这一点。我知道你说的。当然,我下次会对文本应用样式:)
success:function(data){
}
success:function(data){
alert(data)
}
').val()
]').val()
<form id='myFormTag'>
$('#myFormTag').submit(function(e){
e.preventDefault();
$.ajax({
data: new FormData(this),
//other AJax Stuff
success:function(data){
alert(data)
}
});
});