Ajax CodeIgniter Featured Javascript jQuery Web Programming

post Json like getJson in Jquery

jquery 1.4

In Jquery getJson is a great function. it used to Load JSON-encoded data from the server using a GET HTTP request.  In the server side also we can handle json very easly. In PHP just use json_encode () will do the magic. So ajax transportation using PHP and jquery is easy.

the problem is

PHPVersion  Description

5.3.0       The options parameter was added.

5.2.1          Added support to JSON encode basic types.

I am using codeigniter for small projects. So there is a problem with the GET methode.Code Igniter will suppress the Get requests and parameters. some people saying that using GET is not that much good in the case of security. So I searched a postJson function in Jquery and find nothing. Actually the answer is very simple.

$.post('ajax/test.html', function(data) {

is a great function. Just turn on the json using

$post('url',function(data) { the result; },"json");

will give the postJson function. Like this

$.post("test.php", { "func": "getNameAndTime" },
     alert(data.name); // John
     console.log(data.time); //  2pm
   }, "json");

Saved My Life. Great..

One thought on “post Json like getJson in Jquery

  1. I use this:


    <script type="text/javascript" src="/dev/jquery-1.3.2.js"></script>

    <script type="text/javascript" src="/latest/jquery.json-2.2.js"></script>
    var formData = {
    , "email":$("input#email").val()
    , "name":$("input#name").val()
    , "validate":$("input#validate").val()


    type: "POST",

    url: "/comments_photo/add",
    data:’jsonData=’ + $.toJSON(formData),
    dataType: "json",
    success: function(msg) {

    if (msg.success_ok > 0) {

Leave a Reply