CodeIgniter + jQuery + Json how to

Leave a comment

Controller define method like


public function getjson(){
			$arr = array(
				val=>$this->input->post("name")
			);
			echo json_encode($arr);
		}

Define view


$(document).ready(function(){

			$('#bt').click(function(){

				$.ajax({

					url		: "ajax/getjson",
					data	: "name=myname",
					type	: "post",
					dataType: "json",
					success : function(res){
						$('#result').html(res.val);
					},
					error	: function(res){
						alert(res);
					}

				});

			});

		});

How to remove index.php from Codeigniter URL

Leave a comment

To do this just follows the following steps:

  • Open config.php from system/application/config directory and replace

$config[‘index_page’] = “index.php” by $config[‘index_page’] = “”

  • Create a “.htaccess” file in the root of CodeIgniter directory (where the system directory resides), open the file using your favorite text editor, write down the following script and save it:

Windows change to

</pre>
RewriteEngine on
RewriteBase /ci/
RewriteCond $1 !^(index\.php|<span style="color: #ff0000;">js</span>|css|images|javascript)
RewriteRule ^(.*)$ index.php/$1 [L]

Mac change to

RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
  • In some case the default setting for uri_protocol does not work properly. To solve this problem just replace

$config[‘uri_protocol’] = “AUTO” by $config[‘uri_protocol’] = “REQUEST_URI” fromsystem/application/config/config.php

Notepad++ and Zen Coding tips (Windows)

Leave a comment

Setup Zen Coding 

  • Plugins -> Plugin Manager -> Show Plugin Manager
  • Select Zen Coding – Python
  • Click Install
  • Done

Expand Abbreviation -> control + alt + enter

Example. type

html:5

press control alt enter

result is


<!DOCTYPE HTML>
<html lang="en-US">
<head>
	<meta charset="UTF-8">
	<title></title>
</head>
<body>
	
</body>
</html>

Wrapping With Abbreviation -> shift + ctrl + alt + enter

Example. type

About Us
Products
News
Blog
Contact Up

press shift + ctrl + alt + enter

popup appear type

div#header>ul#navigation>li.item$*>a>span

click ok result is

<div id="header">
<ul id="navigation">
	<li class="item1"><a>
 About Us
 </a></li>
	<li class="item2"><a>
 Products
 </a></li>
	<li class="item3"><a>
 News
 </a></li>
	<li class="item4"><a>
 Blog
 </a></li>
	<li class="item5"><a>
 Contact Up
 </a></li>
</ul>
</div>

How to Indent html code(re-format) in notepad++?
– try use plugin XML Tools (Plugins -> XML Tools -> Pretty print .. )

How to do folding in notepad++?
– View -> Fold All, Unfold All, Collapse Current Level, ….