日期:2014-05-16  浏览次数:20383 次

用jQuery进行ajax与后台的交互出现问题
本帖最后由 cscxxx 于 2013-02-22 19:03:38 编辑
刚开始学习利用jQuery进行ajax与后台的交互,参考网上设定如下三个档,但页面一载入就发生三个错(404,4,error),填入资料提交后ie8显示在js的第46行有对象不支持方法,请教怎么解决?

使用ie8测试
jQuery-1.8.3.js
json2.js

js

$.fn.serializeObject = function() {
var o = {};
var a = this.serializeArray();
$.each(a, function() {
  if (o[this.name]) {
   if (!o[this.name].push) {
    o[this.name] = [ o[this.name] ];
   }
   o[this.name].push(this.value || '');
  } else {
   o[this.name] = this.value || '';
  }
});
return o;
};

$(document).ready(
  function() {
   jQuery.ajax( {
    type : 'GET',
    url : 'jasonServlet',
    dataType: 'json',   //返回值类型 
    success : function(data) {
    //if (data && data.success == "true") {
    if (data) {
    alert(data);
    $.each(data, function(i, item) {
     $('#info').html("共" + item.total + "条数据。<br/>"+item.success+"<br/>");
     // $.each(data.data, function(i, item) {
     $.each(item.data, function(i, item) {
       $('#info').append(
         "编号:" + item.id + ",姓名:" + item.username + ",年龄:" + item.age);
      });
     });
     
     }
    },
    error : function(XMLHttpRequest, textStatus, errorThrown) {
                        alert(XMLHttpRequest.status);
                        alert(XMLHttpRequest.readyState);
                        alert(textStatus);
                    }
   });
   $("#submit").click(function() {
    var jsonuserinfo = $.toJSON($('#form').serializeObject());
    alert(jsonuserinfo);
    jQuery.ajax( {
     type : 'POST',
     contentType : 'application/json',
     url : 'http://localhost:8081/TPVFrames/CheckUserLogin',
     data : jsonuserinfo,
     dataType : 'json',
     success : function(data) {
      alert("新增成功!");
    &n