使用$.post()与使用$.get()进行Ajax请求时,其结构和使用方式都相同,主要的区别如下:
GET请求会把参数加载URL后进行传递,而POST请求则是作为HTTP消息的尸体内容发送给Web服务器。
GET方式对传输的数据有大小限制,而POST传递的数据量理论上不受限制。
GET方式请求的数据会被浏览器缓存起来。
使用POST请求Ajax的代码如下:
$.post("student/Upload-addQuestion.action", {
questionTypeName:questionTypeName,
questionsTitle:questionsTitle,
chapterId:chapterId,
questionContent:questionContent,
answerContent:answerContent,
answerExplain:answerExplain
},function(data,textStatus){
alert(data);
$('.question_summary').val("");
$('.quesion_textarea').val("");
$('#question_answer').val();
$('#question_answer_tips').val();
});
这里的questionTypeName是变量名,也可以直接在html中获取,如:
questionTypeName:$('#question_type').val();