不知道你为什么要自己写,一般我是不会自己写,项目里面引入jquery,很轻松啊。
$.ajax({ url:'', data:{ 'param1':'text', 'param2':'text1' }, success:function(result){ alert('加载成功'); }});