Thursday, 10 October 2013

PNR STATUS Mobile Application for PHONEGAP

PNR STATUS Android Application for PHONEGAP 
        In this tutorial you will learn about accessing the pnr status for ticket booking. this is the sample application where completed with the  dummy pnr number.
Android irctc application sample source code to check pnr status,Mobile application to retrieve the pnr info

Get PNR Status for a Ticket - JSON
Service Endpoint: http://www.railpnrapi.com/<PNR_NUMBER>
This api is the private api through which we can access the indian railway pnr status check service
Sample JSON Response Skeleton:
 {
 "ok": "1", 
"tnum": "12805", 
"tname": "JANMABHOOMI EXP", 
"tdate": "25-2-2013", 
"from": "GNT", "to": "SC",
 "class": "CC",
 "charted": true, 
"numofpax": 2,
 "pax": [ { "coach": "D2",
 "berth": "23", 
"quota": "GN", 
"status": "CNF" },
 { "coach": "S2",
 "berth": "43",
 "quota": "GN", 
"status": "CNF" } ] } 
To Work with Phone gap 
Prerequisites :
1.install phonegap icenium 
2.create a project and paste the following code in the index.html page and run the project
<!DOCTYPE html>
<!--
    Licensed to the Apache Software Foundation (ASF) under one
    or more contributor license agreements.  See the NOTICE file
    distributed with this work for additional information
    regarding copyright ownership.  The ASF licenses this file
    to you under the Apache License, Version 2.0 (the
    "License"); you may not use this file except in compliance
    with the License.  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing,
    software distributed under the License is distributed on an
    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
     KIND, either express or implied.  See the License for the
    specific language governing permissions and limitations
    under the License.
-->
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <meta name="format-detection" content="telephone=no" />
        <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" />
        <link rel="stylesheet" type="text/css" href="css/index.css" />
         <!-- JQUERY CSS -->
        <script src="http://code.jquery.com/jquery-1.8.3.min.js"></script>
        <link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.0/jquery.mobile-1.3.0.min.css" />

        <!-- CORDOVA - PHONE GAP -->
        <script type="text/javascript" src="cordova.js"></script>
        <title>Hello World</title>
        <style>
            #container {
    margin: 10px;    
}
table, th, td {
    width:auto;
    border: 1px solid black;
    padding: 5px;
}
        </style>
        <script type="text/javascript">
            
        jQuery(document).ready(function() {
    var host = "http://www.railpnrapi.com/";
    console.log("Setting host to "+host);
    var sample_pnr = "6712133131";
            
    console.log("Setting Sample PNR to "+sample_pnr);
    var url_construct = host + sample_pnr;
    console.log("Full URL Construct is "+url_construct);
    var dataType = "json";
    console.log("Setting response DataType to "+dataType);
    console.log("Now making an AJAX GET request...");
    $.ajax({
        type: 'GET',
        url: url_construct,
        success: function(data) {
            console.log("Received JSON response: "+JSON.stringify(data));
            followthru(data);
        },
        dataType: dataType,
        cache: false
    });
    
    function followthru(rcvd_response) {
        if(rcvd_response.ok == "1") {
            console.log("Everything good...Proceed to process");
            process(rcvd_response);
        } else {
            console.log("Invalid PNR/Service Unavailable. Stop here!");
            alert("Invalid PNR/Service Unavailable");
        }
    }
    
    function process(info) {
        console.log("Started parsing JSON response");
        var traintr = jQuery("table tr#tr2:last");
        var paxpr = jQuery("table#paxinfo tr:last");
        var paxhtml = '';
        traintr.append("<td>"+info.tnum+"</td>");
        traintr.append("<td>"+info.tname+"</td>");
        traintr.append("<td>"+info.tdate+"</td>");
        traintr.append("<td>"+info.from+"</td>");
        traintr.append("<td>"+info.to+"</td>");
        traintr.append("<td>"+info.class+"</td>");
        traintr.append("<td>"+info.charted+"</td>");
        
        for(i=0;i<info.numofpax;i++) {
            paxhtml += '<tr>';
            paxhtml += '<td>';
            paxhtml += info.pax[i].coach;
            paxhtml += '</td>';
            paxhtml += '<td>';
            paxhtml += info.pax[i].berth;
            paxhtml += '</td>';
            paxhtml += '<td>';
            paxhtml += info.pax[i].quota;
            paxhtml += '</td>';
            paxhtml += '<td>';
            paxhtml += info.pax[i].status;
            paxhtml += '</td>';
            paxhtml += '</tr>';
        }
        paxpr.after(paxhtml);
        console.log("Response parsing done");
    }
});
        </script>
    </head>
    <body>
        <div data-role="page" id="container">
           <input type="text" id="pnrnumber" size="20" name="pnrnumber" value="" placeholder="pnr number" />
<table id="traininfo"><tr id="tr1">
    <th>Train #</th>
    <th>Train Name</th>
    <th>Train Date</th>
    <th>From</th>
    <th>To</th>
    <th>Class</th>
    <th>Chart Prepared</th>
</tr>
    <tr id="tr2"></tr>
</table>
<br />
<br />
<table id="paxinfo">
    <tr id="pr1">
        <th>Coach</th>
        <th>Berth</th>
        <th>Qouta</th>
        <th>Status</th>
    </tr>
</table>
</div>
    </body>
</html>
The pnr number is hard coded you can retrieve it from text box and have some function.
you can add css to design the table view in what model you want.
Key points:
Android, ios , bada, windows mobile application to check pnr status 

Disclaimer: This website is not affiliated with The Ministry of Railways, Government of India and does not store in its database any content of Indian Railways websites. For the official website, please visit Indian Railways 


6 comments:

  1. getting PNR STATUS Mobile Application is really nice

    Indian railway pnr status

    ReplyDelete
  2. this site is very help ful for all over indians.lot of stuff is here in this website am already bookmarked for revisiting…………………

    PNR STATUSverification made easy through our website via mobile calling & sms & website also. Login……………RAILHUB.IN

    PNR STATUSchecking only Indian railways journey’s in india when berth is confermed or not.

    ReplyDelete
  3. Check PNR status in a single click
    check pnr status:pnr status

    ReplyDelete
  4. This comment has been removed by the author.

    ReplyDelete
  5. Have you ever wondered what does a PNR Status Inquiry means? We bring you some quick facts which would clear all your doubts about what PNR is and the usual pain points which often confuses a lot of travellers. PNR, if simply described, is the travel record of a passenger or a group of passengers who are travelling together which is saved in the computer database of the reservation system. It is a 10-digit alpha-numeric which is printed on the ticket itself and is required for making any travel related query. Check out pnr status of your ticket with a single click.

    ReplyDelete