For smart Primates & ROBOTS (oh and ALIENS ).

Showing posts with label ajax. Show all posts
Showing posts with label ajax. Show all posts

Wednesday, March 25, 2015

Email Blaster

Email Blaster
*Features
- Send unlimited emails.
- Send test email, so you can see your email format and looks.
- Show real time progress in counting sent emails.
- Show progress in percentage(%)
- Send email both format Text and HTML format.
- Alternate Solution of Cron Job(Less feature).
- Alternate Solution of SQL Agent Job(Less feature).
- Solution of Script Timeout.






















































Share:

Tuesday, March 17, 2015

Lazy load image

If your site is loading slow then then main causes could be heavy images. So if you remove those images then your site load fast. but if those images are the main features of your product or web site then you will not remove those images. So what will you do?
Load those images one by one on demand then it will make difference when loading site.
So the solution is lazy load image will help you to load your site fast.

To implement lazy load image you need to download jquery.js and jquery.lazy.js from jquery site

I have made three methods to load image lazy, Use one method from below 3 methods:
// Method 1
    jQuery(document).ready(    function() { jQuery("img.lazy").lazy(    {
                                                                    effect: "fadeIn",
                                                                    effectTime: 1500 ,
                                                                    enableThrottle: true,
                                                                    throttle: 250
                                                                    }
                                                                );
                                       }
                          );

// Method 2
    //jQuery(document).ready(function() { jQuery("img.lazy").lazy({ effect: "slideIn", effectTime: "slow" }); });

//Method 3
    //jQuery(document).ready(function() { jQuery("img.lazy").lazy({ effect: "fadeIn", effectTime: 1500 }); });


 Use in HTML as below:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
  <script type="text/javascript" src="jquery.js"></script> 
  <script type="text/javascript" src="jquery.lazy.js"></script>
  <script>
    jQuery(document).ready(    function() { jQuery("img.lazy").lazy(    {
                                                                    effect: "fadeIn",
                                                                    effectTime: 1500 ,
                                                                    enableThrottle: true,
                                                                    throttle: 250
                                                                    }
                                                                );
                                       }
                          );
    // alternative 1
    //jQuery(document).ready(function() { jQuery("img.lazy").lazy({ effect: "slideIn", effectTime: "slow" }); });
    // alternative 2
    //jQuery(document).ready(function() { jQuery("img.lazy").lazy({ effect: "fadeIn", effectTime: 1500 }); });
  </script>
</head>
<body>
<img class="lazy" data-src="1.jpg" src="" border="0" alt="Lazy Image" /><br/><br /><br/><br /><br/><br /><br/><br />
<img class="lazy" data-src="2.jpg" src="" border="0" alt="Lazy Image" /><br/><br /><br/><br /><br/><br /><br/><br />
<img class="lazy" data-src="3.jpg" src="" border="0" alt="Lazy Image" /><br/><br /><br/><br /><br/><br /><br/><br />
<img class="lazy" data-src="4.jpg" src="" border="0" alt="Lazy Image" /><br/><br /><br/><br /><br/><br /><br/><br />
<img class="lazy" data-src="5.jpg" src="" border="0" alt="Lazy Image" /><br/><br /><br/><br /><br/><br /><br/><br /><img class="lazy" data-src="23.jpg" src="" border="0" alt="Lazy Image" /><br/><br /><br/><br /><br/><br /><br/><br />
<img class="lazy" data-src="24.jpg" src="" border="0" alt="Lazy Image" /><br/><br /><br/><br /><br/><br /><br/><br />
<img class="lazy" data-src="25.jpg" src="" border="0" alt="Lazy Image" /><br/><br /><br/><br /><br/><br /><br/><br />

...... LOAD MORE IMAGES HERE ....
...... LOAD MORE IMAGES HERE ....
...... LOAD MORE IMAGES HERE ....
...... LOAD MORE IMAGES HERE ....


<img class="lazy" data-src="26.jpg" src="" border="0" alt="Lazy Image" /><br/><br /><br/><br /><br/><br /><br/><br />
<img class="lazy" data-src="27.jpg" src="" border="0" alt="Lazy Image" /><br/><br /><br/><br /><br/><br /><br/><br />
<img class="lazy" data-src="28.jpg" src="" border="0" alt="Lazy Image" /><br/><br /><br/><br /><br/><br /><br/><br />
<img class="lazy" data-src="29.jpg" src="" border="0" alt="Lazy Image" /><br/><br /><br/><br /><br/><br /><br/><br />
<img class="lazy" data-src="30.jpg" src="" border="0" alt="Lazy Image" /><br/><br /><br/><br /><br/><br /><br/><br />
<img class="lazy" data-src="31.jpg" src="" border="0" alt="Lazy Image" /><br/><br /><br/><br /><br/><br /><br/><br />
<img class="lazy" data-src="32.jpg" src="" border="0" alt="Lazy Image" /><br/><br /><br/><br /><br/><br /><br/><br /></body>
</html>
Share:

Thursday, January 15, 2015

TypeError e is undefined in jquery json

Problem:

jQuery is good JavaScript library. It provide lot of facilities,one of famous facility is it's Ajax. but some time you can get a error message "TypeError e is undefined" or "TypeError: e is undefined" in jQuery Ajax error "TypeError: e is undefined" specially when working with Ajax and JSON.
Normally it occurs when you trying to access a variable without  defined or declare in JavaScript. But when you declare all the variable and error still coming then how to remove it?

Look below code:

In file1.php file

----------------------------------------------------------------------
$c_id=$_GET['c_id'];
$s_id=$_GET['s_id'];
// get result from Database
$rs=$util->get_all_code($c_id, $s_id) ;
$rows = array();
while ($row = $rs->fetch_array(MYSQLI_BOTH)) {
     $rows[]=$row;
}
print '{"All_codes":'. json_encode($rows).'}';
----------------------------------------------------------------------
Keep not that "All_codes" is the top heading array in the above JSON result. And you will use that "All_codes" in jQuery result fetch loop as below code:

 In file2.php file

----------------------------------------------------------------------
 $.ajax({
                type: 'GET', async: false, cache: false, timeout:5000, url: 'ajax_util.php',
                data: { c_id: 1,s_id:2 },
                dataType: 'json',
                success: function (data) {
                                                         $.each(data.All_code, function(idx, obj) {
                                                            var nm=obj.nm;
                                                         });
                                                       }
});
Keep in mind that you have used "All_code" instead of "All_codes"
----------------------------------------------------------------------

Solution:

It's solution is re-again check the variable name in JSON result in PHP and jQuery.

Example:

In file1.php file

----------------------------------------------------------------------
$c_id=$_GET['c_id'];
$s_id=$_GET['s_id'];
// get result from Database
$rs=$util->get_all_code($c_id, $s_id) ;
$rows = array();
while ($row = $rs->fetch_array(MYSQLI_BOTH)) {
     $rows[]=$row;
}
print '{"All_codes":'. json_encode($rows).'}';
----------------------------------------------------------------------

 In file2.php file

 $.ajax({
                type: 'GET', async: false, cache: false, timeout:5000, url: 'file1.php',
                data: { c_id: 1,s_id:2 },
                dataType: 'json',
                success: function (data) {
                                                         $.each(data.All_codes, function(idx, obj) {
                                                            var nm=obj.nm;
                                                         });
                                                       }
});
Keep in mind that you have used "All_codes"



Share:

Wednesday, January 07, 2015

ajax in jquery

The simple way to use ajax in jquery is below:

$.ajax({
        type: 'GET', async: false, cache: false, timeout:5000, url: 'ajax_util.php?'+new Date().getTime(),
        data: { f_for: 'get_topic_by_lesson_id',lesson_id:1},
        dataType: 'json',
        success: function (data) {    
            $.each(data.get_topic, function(idx, obj) {
                var topic_id=obj.topic_id;
                var topic_nm_val=obj.topic_nm;
            $('#topic_nm').append('<option value="' + topic_id + '">' +topic_nm_val+ '</option>'); 
            });
        }
    });

The problem is that here we are passing type, async,cashe timeout,data and dataType each time. so can we short cut it? yes we can shortcut it as below:

var variableAndValue={f_for: 'full_test',class_id:class_id,subject_id:subject_id };
var data=myajaxGetJSON('ajax_util.php?'+new Date().getTime(),variableAndValue);

Definition of  myajaxGetJSON function is as below:

function myajaxGetJSON(url,f_for) {
     var result="";
     $.ajax({
        type: 'GET', async: false, cache: false, timeout:5000, url: url,
        data: f_for,
        dataType: 'json',
        success: function (data) {
        result = data;    
        }
    });
    return result;
}
In above function you can use POST instead of GET method.

How use above function?

var class_id=1;
var  subject_id=1;
var variableAndValue={f_for: 'get_emp',class_id:class_id,subject_id:subject_id };
var data=myajaxGetJSON('ajax_util.php?'+new Date().getTime(),variableAndValue);
$.each(data.list_of_emp, function(idx, obj) {
//////   the obj variable is holding all the data
        var q_id=obj.q_id;
        var question_parts=obj.question_parts;
        var question_path=obj.question_path;
        var mark=obj.mark;
});

What about in the 'ajax_util.php'  

$f_for=$_GET['f_for'];
if($f_for=="get_emp") {
        $class_id=$_GET['class_id'];
        $subject_id=$_GET['subject_id'];
        $rs=$full_test->get_one_full_book_random($class_id,$subject_id,$marks,$not_ids);
        // The $rs is holding the data result set from mysql
        $rows = array();
        while ($row = $rs->fetch_array(MYSQLI_BOTH)) {
            $rows[]=$row;
        }
        print '{"list_of_emp":'. json_encode($rows).'}';
}






Share:

Friday, October 25, 2013

Ajax in struts

How to use ajax in struts and hibernate.

Ajax is very important in website coding.
Here I am demonstrating how to use jquery ajax in struts and hibernate.


struts-config.xml
--------------------------
<action input="/" path="/amittest" scope="request" type="com.test.actions.AmitTestAction" parameter="method">
<forward name="success" path="/Webs/Input/amittest.jsp"/>
</action>
====================================================


query.hbm.xml
-----------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
  <sql-query cache-mode="ignore" cacheable="false" flush-mode="always" name="chkBook"> SELECT COUNT(*) FROM book_master WHERE code_id=:code AND serial_id>=:serial </sql-query>
</hibernate-mapping>
====================================================

MyUtilDao.java
------------------------------
package dao;
import org.hibernate.CacheMode;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;
import plugins.HibernateSessionFactory;
public class MyUtilDao {
    public int chkBook(int code,int serial){
        Session ssn = null;
        ssn = HibernateSessionFactory.getSession();
        ssn.setCacheMode(CacheMode.GET);
        Query qry = ssn.getNamedQuery("chkBook");
        qry.setParameter("code", code);
        qry.setParameter("serial", serial);
        Object tot = qry.uniqueResult();
        int total = 0;
        if (tot != null) {
            total = Integer.parseInt(tot.toString());
        } else {
            total = 0;
        }
        return total;
    }
 
}
====================================================

AmitTestAction.java
-------------------------
package mytest.actions;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.sql.*;
import java.util.Date;
import java.text.DateFormat;
import java.text.SimpleDateFormat;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionForward;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;
import dao.MyUtilDao;
import plugins.HibernateSessionFactory;

public class AmitTestAction  extends org.apache.struts.actions.DispatchAction {
     private final static String SUCCESS = "success";
     public ActionForward showForm(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response) throws Exception {
       
         MyUtilDao myUtiDaoObj=new MyUtilDao();
       
         String ffor= request.getParameter("ffor");
         if(ffor.compareTo("chkBook")==0) {
            int code= Integer.parseInt(request.getParameter("code"));
            int erial= Integer.parseInt(request.getParameter("serial"));
            int total=myUtiDaoObj.chkBook(code,serial);
            request.setAttribute("total", total);
            request.setAttribute("ffor", "chkBook");
         }
         return mapping.findForward(SUCCESS);
      }
}
====================================================
amittest.jsp
<%
if(request.getAttribute("ffor")!=null) {
    if(request.getAttribute("ffor").toString().compareTo("chkBook")==0) {
        out.print(request.getAttribute("total"));
    }
}
%>
====================================================
BookAdd.jsp

<input type="button" name="btn1" value="Button" onclick="dotest();"/>
<html:button property="button" value="Save" onclick="do_save()"/>
<script>

 var code=222;
var serial=111;
function do_save() {
        var ajaxans="";
        $.ajax({
                    url: "amittest.do?method=showForm",
                    type: "POST",
                    async: false,
                    cache: false,
                    data:   { 'ffor':'chkBook',
                              'code':code,
                              'serial':serial},
                    success: function(html) {
                             ajaxans=html;
                            }
                }
             );
       if(ajaxans=="1" || parseInt(ajaxans)==1) {
           alert("This is already exists");
           return;
       }    
        var r=confirm("Do you want to save?");
        if (r==true) {
            document.forms[0].action="BookMasterAdd.do?method=processForm";
            document.forms[0].submit();
        }
    }

   function dotest() {
       /*$.post("http://localhost:8080/mytest/amittest.do?method=showForm",{'method':'showForm'},function(ans) {
alert(ans);
});*/
      /*// done
       *$.post("amittest.do?method=showForm",{'method':'showForm'},function(ans) {
alert(ans);
});*/
      /* done
       * $.post("amittest.do?method=showForm",function(ans) {
alert(ans);
});*/
      /* $.get("amittest.do?method=showForm",function(ans) {
alert(ans);
});*/
     
      /* $.get("amittest.do?method=showForm",{'val1':'Hi'},function(ans) {
alert(ans);
});*/  
   
      /*   $.post("amittest.do?method=showForm",{'val1':'Hi'},function(ans) {
alert(ans);
});*/
    /*  $.post("amittest.do?method=showForm",{'ffor':'chkExistReceiptBookMaster',
                                            'zone_code':'8004500',
                                            'frm_serial':'11'
                                           },function(ans) {
alert(ans);
});*/
}
</script>
====================================================



Share:

Ads Inside Post

Powered by Blogger.

Archive