jQuery实现ajax跨域
1、dataType:'jsonp'2、type: 'get'3、把要传的参数以url方式传出去 url:'http://gameapi.feiliu.com/lqzg?tel='+telnumber,JS代码
php代码(CI框架)
public function index() { header('Content-Type:text/html;Charset=utf-8'); $tel = $_GET['telnumber']; if(! preg_match("/1[3458]{1}\d{9}$/",$tel)){ $key = -1; $mes = '手机号无效!'; }else{ //检查号码是否第一次领取 if( $this->gamem->test_phone($tel)){ $key = -1; $mes = '手机号已经领取过!'; }else{ //随机选取一个code $code = $this->gamem->get_code(); if($code){ //将该用户信息插入 $ret = $this->gamem->insert_user($tel); if($ret){ $key = 1; $mes = $code; } } } } $data = array( 'key' => $key, 'mes' => $mes ); echo $_GET['jsoncallback'] . "(".json_encode($data).")"; exit; }