Javascript ajaxjson方法405
我不理解我的错误,我想用AJAX在我的JSON文件中添加新数据: 我的脚本:Javascript ajaxjson方法405,javascript,jquery,ajax,json,Javascript,Jquery,Ajax,Json,我不理解我的错误,我想用AJAX在我的JSON文件中添加新数据: 我的脚本: function Question(title, fA, sA){ this.title = title; this.fA = fA; this.sA = sA; } $(function() { $('#form').submit(function(event){ event.preventDefault(); var title = $('#ti
function Question(title, fA, sA){
this.title = title;
this.fA = fA;
this.sA = sA;
}
$(function() {
$('#form').submit(function(event){
event.preventDefault();
var title = $('#title').val();
var fA=$('#firstAlternative').val();
var sA=$('#secondAlternative').val();
var q1 = new Question(title,fA,sA);
$.ajax({
url:"http://localhost:5000/gree/questions",
type:"POST",
contentType:"application/json",
data : JSON.stringify(q1),
dataType:"json",
jsonpCallback:'jsonCallback',
jsonp:false,
success:function(data){
alert("HAHAHAHAHHAHAH");
},
error: function(){console.log('Error');}
});
return false;
});
}))
我的表格:
我的表单是基本的,具有良好的id和method=“POST”
问题标题
Réponse 1
Réponse 2
我有错误405(不允许)。在ajax中没有成功,只是出错…当我删除ajax中的类型时,它们是成功的,但数据没有添加HTTP 405意味着不允许使用HTTP方法(例如POST)。您确定允许POST(例如,不仅允许GET)吗?是的,您是对的,但是当我进入localhost:5000/gree/questionsWell时,它没有添加的数据当您调用该路由时,“服务器”做什么?我使用Python:Flask所以SQLAlchemy。
<form id="form" name="formquestions" style="text-align:center;" method="POST">
<p>
<h3>Titre de la question </h3><input type="text" id="title" style="height:50px;font-size:14pt;" size="50" required>
</p>
<p>
<h3>Réponse 1 </h3><input style="height:50px;font-size:14pt;" size="50" type="text" id="firstAlternative" required>
</p>
<p>
<h3>Réponse 2 </h3><input style="height:50px;font-size:14pt;" size="50" type="text" id="secondAlternative" required>
</p>
<p>
<input id="buttonquestion" class="btn-success btn" style="height:50px;font-size:14pt;" type="submit" value=" Créer la question " />
</p>
</form>