分类: 前端

  • axios 参数为payload的解决方法

    1. 添加头部headers

      // 新创建 axios 实例配置
      const $axios = axios.create({
      baseURL: ‘http://domain.com’,
      timeout: 5000,
      headers: {
      ‘Content-Type’: ‘application/x-www-form-urlencoded’,
      ‘sessionId’: Lockr.get(“sessionId”),
      ‘authKey’: Lockr.get(“authKey”),
      }
      });

    2. 参数序列化

      var qs = require(‘qs’);
      axios.post(‘/foo’, qs.stringify({ ‘foo’: ‘bar’ });

    见 https://github.com/mzabriskie/axios/blob/master/README.md#using-applicationx-www-form-urlencoded-format

  • 获取 ajax return 的返回值

    function check_phone (phone) {
    $.ajax({

    url:URL,//请求的url地址

    dataType:”json”, //返回格式为json

    timeout: 10000,

    async:ture,//请求是否异步,默认为异步

    data:{phone:phone}, //参数值

    type:”POST”, //请求方式

    beforeSend:function(){

    },

    success:function(req){

    if(req.status == 0){

    return false;

    }else{

    return true;

    }

    },

    complete:function(){

    },

    error:function(XMLHttpRequest, textStatus, errorThrown){

    return false;

    }

    });

    }

    上面的函数,想返回true和false,在执行alert(check_phone(phone))时候是undefined,感觉在ajax中返回实际上函数没有返回值,应该在ajax外面执行return操作。

    function check_phone (phone) {

    var res = false;

    $.ajax({

    url:URL,//请求的url地址

    dataType:”json”, //返回格式为json

    timeout: 10000,

    async:false,//请求是否异步,默认为异步

    data:{phone:phone}, //参数值

    type:”POST”, //请求方式

    beforeSend:function(){

    },

    success:function(req){

    if(req.status == 0){

    res=false;

    }else{

    res=true;

    }

    },

    complete:function(){

    },

    error:function(XMLHttpRequest, textStatus, errorThrown){

    return false;

    }

    });

    return res;

    }

    注意:async:false。设置为同步的,必须等ajax执行完,返回相应返回值,否则直接return初始的var res=false了。

  • 通过传递session_id解决uploadify上传PHP中丢失SESSION值的问题

     

    由于uploadify通过flash提交上传的文件,会导致在接收文件的PHP端出现获取SESSION值为空的情况,如果你要在PHP端验证用户的登录状态或验证用户输入的验证码是否正确你就需要解决SESSION取值的问题,下面给出uploadify上传中获取SESSION的方法:

    (更多…)

  • JS日历控件

    <link rel=”stylesheet” type=”text/css” href=”/js/calendar/calendar-blue.css”/>
    <script type=”text/javascript” src=”/js/calendar/calendar.js”></script>

    <tr>
    <th width=”120″>时间选择 :</th>
    <td>
    <input type=”text” name=”time_start” id=”time_start” class=”date” size=”12″ value=”{$time_start}”>

    <input type=”text” name=”time_end” id=”time_end” class=”date” size=”12″ value=”{$time_end}”>
    </td>
    </tr>

    (更多…)

  • sorttable对表格排序

    本教程讲述了如何来实现对表格排序的,只需为你想要排序的表格添加一个名为“sortable ”的class ,就可以实现表格的排序功能

    第一步: 调用sorttable.js
    创建一个新的页面并在 <head>标签里面调用Sorttable.js:

    <script src=“sorttable.js” type=“text/javascript”></script>

    (更多…)

  • AJAX传参,360正常,IE,chrome接收到的参数没值

    客服端发送到服务器代码

    <a value=”<?php echo $row_Recordset_task[‘test02’];?>” onclick=”showUser(this.value)”><?php echo $row_Recordset_task[‘test02’];?></a>

    <div id=”txtHint”></div>

    (更多…)