jquery - fail in transmitting data in ajax -


i want make vote page. when click "", amount of vote plus meets "404 not found".(there no vote2.jsp in project because want refresh part of page.)

vote.jsp <body> <div class="testspan" data-id="1"><span>vote a</span>  num:<em>0</em></div> <div class="testspan" data-id="2"><span>vote b</span> num:<em>0</em></div> <div class="testspan" data-id="3"><span>vote c</span> num:<em>0</em></div> <div class="testspan" data-id="4"><span>vote d</span> num:<em>0</em></div> </body> ajax:     $(".testspan").click(function(){     var xsid = $(this).attr("data-id");     $.post("/vote/vote2",{         xsid:xsid     },function(data, textstatus){         var xsmap = data.xsmap;         $(".testspan").each(function(){             var id = $(this).attr("data-id");             $(this).find("em").html(xsmap[id]);         });     }, "json"); });  controller:     @requestmapping(value="/vote/vote2") public net.sf.json.jsonobject vote(int xsid){     net.sf.json.jsonobject json = new net.sf.json.jsonobject();     userservice.vote(xsid);     json.put("xsmap", userserviceimpl.xsmap);     return json; }  

you need not have create vote2.jsp file. error valid, haven't specified context path in ajax url request.

to solve problem.

  1. use developer tools of browser , locate url raised ajax.
  2. the url should include context path.
  3. verify dispatcherservlet settings (in case using spring). check post.

Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -