jquery使用post进行提交,但返回的是404错误,这是什么情况呢?
1.记录下发生404错误的链接;
2.在服务器端直接输出出现“错误”的链接的内容,看看可不可以;
3.如果不可以,说明是链接有问题;如果可以,检查jq发送的post请求,看看参数有没有被转义;
4.如上面都没问题,那就是服务器的连接有问题,不稳定
如何给ajax回调函数参数传值?
具体的传递参数的语句是:xmlHttp.onreadystatechange=function(){callbackFun(参数);} 关于ajax回调函数的定义及用法:ajax() 方法通过 HTTP 请求加载远程数据。 该方法是 jQuery 底层 AJAX 实现。简单易用的高层实现见 $.get, $.post 等。$.ajax() 返回其创建的 XMLHttpRequest 对象。大多数情况下无需直接操作该函数,除非需要操作不常用的选项,以获得更多的灵活性。 最简单的情况下,$.ajax() 可以不带任何参数直接使用。 注意:所有的选项都可以通过 $.ajaxSetup() 函数来全局设置。
javascript实现json页面分页实例代码?
用jquery ajax异步技术($.post))提交页面显示记录的条数(pageSize)以及要显示的是第几页(pageNo)到服务器,服务器根据这条数进数据库去查询数据(MySQL数据库用limit,Oracle用rownum伪列来实现分页查询),前台pageNo每次加一。分页所需要的页数等于数据库中查询到的记录总条数除于pageSize。
把页数,查询的数据response给前台页面。再用bootstrap分页条插件。把分页条的页码超链接中的页数动态获取。
总页数在数据库中已经拿到了,修改一下可用
用java写个接口实现数据对接?
application/x-www-form-urlencoded:
application/json:
通过上面例子发现,结构简单的时候formdata数据更简单,结构复杂的时候(array)JSON数据更简单。
题目问到Java接口,应该分三种情况。
如果是JSP等服务器端模板技术,再加上一些jQuery AJAX。
POST的时候,默认contentType都是application/x-www-form-urlencoded。可改成application/json,看自己。
如果用前端框架,Angular、React、Vue。
POST的时候,默认contentType都是application/json。建议用JSON,别改。JSON就是JS的一个子集,既方便JS解析,也方便人读。
Java服务器端对其他服务器端通信。
其实更建议用XML,特别是和第三方服务通信的时候。如果公司内部自己的几个Java服务通信,用JSON就好。
现在Java Web开发,最常见的是上面第2种情况。所以,当用Spring MVC的时候,建议用@RestController
如果用@Controller,需要这么写:
如果用@RestController,不需要写@ResponseBody,也不需要指定consumes和produces类型,默认都是application/json。可以简化成这样:
还没有评论,来说两句吧...