0

can we write two ajax success function on same page because sometimes its work sometime not doajaxpost function is to load data in 2nd dropdown list when 1st dropdown list onchange function call by using ajax and searching function is to load data in table by using ajax but it sometime get execute properly sometimes not showing any result

 function doAjaxPost(instituteId) {

        alert(instituteId);
        // get the form values  
        /* var name = $('#name').val();
        var education = $('#education').val(); */
        $.ajax({
            type : "POST",
            url : "/paymentGateway/merchant",
            dataType : "json",
            data : "institutionId=" + instituteId,
            success : function(data) {
                // we have the response  
                alert(data + "hiee");
                var $merchantId = $('#merchant');

                $merchantId.find('option').remove();
                $("#merchant").append("<option value='ALL'>ALL</option>");
                $.each(data, function(key, value) {
                    $('<option>').val(value.merchantId).text(value.merchantId)
                            .appendTo($merchantId);
                });

            },
            error : function(e) {
                alert('Error: ' + e);
            }
        });
    }

    function searching() {
        // get the form values  
        var institutionId = $('#instiuteId').val();
        var merchantId = $('#merchant').val();
        var userType = $('#userType').val();
        var userStatus = $('#userStatus').val();
        var userId = $('#userId').val();

        alert("insti=" + institutionId + "mecrhant=" + merchantId + "usertyep="
                + userType + "users=" + userStatus + "userid=" + userId);
        $.ajax({
            type : "POST",
            url : "/paymentGateway/searching",
            dataType : "json",
            data : {
                institutionId : institutionId,
                merchantId : merchantId,
                userId : userId,
                userStatus : userStatus,
                userType : userType
            },
            success : function(data) {
                // we have the response  
                alert(data);
                /*  var $merchantId = $('#dynamictable');
                   $merchantId.find('table').remove(); 
                 $('#dynamictable').append('<table></table>');
                 var table = $('#dynamictable').children();  */

                $("#tablenew tbody tr:has(td)").remove();

                $.each(data, function(key, value) {
                    /*        alert(value.institutionId);  */
                    $('#tablenew tbody:last').append(
                            "<tr><td>" + value.userId + "</td><td>"
                                    + value.firstName + "</td><td>"
                                    + value.userStatus + "</td><td>"
                                    + value.userType + "</td><td>"
                                    + value.userAddedBy + "</td><td>"
                                    + value.userRegisteredDateTime
                                    + "</td><td>" + value.recordLastUpdatedBy
                                    + "</td><td>" + value.recordLastUpdatedTime
                                    + "</td></tr>");
                });

            },
            error : function(e) {
                alert('Error: ' + e);
            }
        });
    }
Cœur
  • 37,241
  • 25
  • 195
  • 267
jerry
  • 11
  • 3

2 Answers2

1

It could be a caching issue, try to setup

$.ajaxSetup({ cache: false });

See How to prevent a jQuery Ajax request from caching in Internet Explorer?

Community
  • 1
  • 1
selvinsource
  • 1,837
  • 2
  • 17
  • 20
0

I got the same problem. You'll have to use the class instead of ID to make it work. Use $(".merchant") to replace $("#merchant"), and update 'merchant' to be a class.

Deceleven
  • 25
  • 1
  • 5