jsonp 測試頁面 前端 html 及後端 php 範例

HTML:

<html>
<head>
<META HTTP-EQUIV="CONTENT-TYPE" 
CONTENT="text/html; charset=UTF-8">
<script type='text/javascript' src='http://code.jquery.com/jquery-1.10.2.js'></script>
<script type='text/javascript'>
function show_msg(msg){
	alert(msg);
}
$(function(){
	$.ajax({
		type:'get',
		async:false,
		crossDamain:true,
		cache:false,
		url:'http://carbonfootprint.toyoink-ct.com.tw/carbonfootprint/login_valid',
		dataType:'jsonp',
		jsonCallback:'show_msg',
		data:{account:'jerry',passwd:'justdoit'}
	});
});
</script>
</head>
<body>
</body>
</html>

PHP:

    public function login_valid(){
        $account=$this->input->get('account');
        $passwd=$this->input->get('passwd');
        $query=$this->db->query("select * from carbon_passwd where id='{$account}' and passwd='{$passwd}';");
        if($query->num_rows()>0){
            $this->session->set_userdata($query->row(1));
            //print_r($this->session->all_userdata());
            echo "show_msg('密碼對了^^');";
        }
        else{
            echo "show_msg('你打的帳號:{$account},密碼:{$passwd}不對喔!!');";
        }
    }

發表迴響

在下方填入你的資料或按右方圖示以社群網站登入:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / 變更 )

Twitter picture

You are commenting using your Twitter account. Log Out / 變更 )

Facebook照片

You are commenting using your Facebook account. Log Out / 變更 )

Google+ photo

You are commenting using your Google+ account. Log Out / 變更 )

連結到 %s