允许使用AjAx和post方法将数据发送到servlet
function validate (user_value){ var name = user_value; $.ajax({ url:"ggs.erm.servlet.setup5.AjaxS", data:{ namee :name}, success:function(){ alert("worked"); } }); }
这是我的代码。 有什么问题吗? 任何类型的语法或语义错误。
问题:无法在URL中向servlet发送参数。?????
如果您希望servlet的doPost
方法处理请求,则应添加值为post
属性type
。
function validate (user_value){ var name = user_value; $.ajax({ url:"ggs.erm.servlet.setup5.AjaxS", data:{ namee :name}, type: 'post', success:function(){ alert("worked"); } }); }
这样您的Ajax请求将发布而不是get(默认值)。
看来你的函数在doc ready
handler中检查出来,看看是否有帮助:
function validate (user_value){ var name = user_value; $.ajax({ url:"ggs.erm.servlet.setup5.AjaxS", type:'POST', //<-----------------added this data:{ namee :name}, success:function(data){ if(data){ alert("worked"); } }, error:function(){ alert('not worked.'); } }); } $(document).ready(function(){ // your other code stuff for calling the function });