mercredi 6 mai 2015

highstock chart when loading via ajax has jerky behavior

I'm using HighStock api and setExtremes callback to load data from server.

When I change the extremes, the whole chart just jerks to some values (x axis changes so do the lines) until the data is returned from the server.

It looks highly unprofessional, as if an error corrected on runtime.

Any change the 'loading' comes and then the new data comes smoothly?

here's the fiddle

if !is_code_accompanied
  stack_overflow = doesnt_let_me_post()
end

How's 504 response header handled in ajax request in jquery?

I have an ajax call from client, that looks like that:

$.ajax({
            'url': '/converter/ajax-make-corrections/',
            'data': {

                corrections: JSON.stringify(globalCorrrectionsObject)
            },
            type: 'POST',
            success: function(data) {

            }
        })

This action send pretty big file to server to do some server job. The trouble is that there is timelimit on server - 30 minutes. After that server closes a connection with 504 errror (here is what I see in nginx access log file):

[06/May/2015:09:13:33 +0300] "POST /converter/ajax-make-corrections/ HTTP/1.1" 504

and at the same tim in nginx error.log file

*1799741 upstream timed out (110: Connection timed out) while reading response header from upstream, client: 

There is no errors in apache log.

And here is what happened: action from browser was restarted 9 times exactly 30 minutes after each other. Since action in browser can not be start manually second time with same data, my best guess is that $.ajax action was restarting itself after getting 504 response. Is it possible? How $.ajax handles 504 response? Will it restart itself sending same data again?

Having an Issue In Using Angular Js with DNN7

I have created a user defined controller and than add a module in dnn7(Having resource of my user defined controller) and created a page in dnn7 and than access my newly created Module on it.But It shows me my HTML Page only means Submit button is not working and in Grid as well it's just showing me the name of fields.

For Ex:-

function EmpCtrl($scope) {
    $scope.getEmployee = function () {
        $.ajax({
            type: "POST",
            url: "http://ift.tt/1dMBcXF",
            data: "{}",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (msg) {
                 $scope.Emp = msg.d;
            }
        });
    };

 $scope.save = function () {
        $.ajax({
            type: "POST",
            url: "http://ift.tt/1dMBfTa",
            data: "{'empID':'" + $("#txtEmpID").val() + "','firstName':'" + $("#txtEmpFirstName").val() + "','lastName':'" + $("#txtEmpLastName").val() + "','address':'" + $("#txtEmpAddress").val() + "','city':'" + $("#txtCity").val() + "','pincode':'" + $("#txtPinCode").val() + "','state':'" + $("#txtState").val() + "','country':'" + $("#txtCountry").val() + "'}",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (msg) { 
                alert(msg.d);
            },
            error: function (msg) {
                alert(msg.d);
            }
        });
    };

<body>
    <form id="form1" ng-app="MyApp" ng-controller="EmpCtrl" ng-submit="save() ">
        <div style="text-align: center;">
            <img alt="" src="banner.jpg" />
        </div>
        <br />
        <div style="font-family: Verdana; font-size: 12px; margin-left: 450px;">
            <table>
                <tr>
                    <td style="text-align: right;"></td>
                    <td>
                        <input type="hidden" id="txtEmpID" value="0" ng-model="EmpID" />
                    </td>
                </tr>
                <tr>
                    <td style="text-align: right;">First Name :
                    </td>
                    <td>
                        <input type="text" id="txtEmpFirstName" ng-model="EmpFirstName" autocomplete="off" />
                    </td>
                </tr>
                <tr>
                    <td style="text-align: right;">Last Name :
                    </td>
                    <td>
                        <input type="text" id="txtEmpLastName" ng-model="EmpLastName" autocomplete="off" />
                    </td>
                </tr>

                <tr>
                    <td style="text-align: right;">Address :
                    </td>
                    <td>
                        <textarea id="txtEmpAddress" cols="20" rows="2" ng-model="EmpAddress"></textarea>
                    </td>
                </tr>
                <tr>
                    <td style="text-align: right;">City :
                    </td>
                    <td>
                        <input type="text" id="txtCity" ng-model="EmpCity" autocomplete="off" />
                    </td>
                </tr>
                <tr>
                    <td style="text-align: right;">Pin Code :
                    </td>
                    <td>
                        <input type="text" placeholder="Enter Digits Only" id="txtPinCode" ng-model="EmpPincode" autocomplete="off" onkeypress="return isNumber(event)" />
                    </td>
                </tr>
                <tr>
                    <td style="text-align: right;">State :
                    </td>

                    <td>
                        <input type="text" id="txtState" ng-model="EmpState" autocomplete="off" />
                    </td>
                </tr>
                <tr>
                    <td style="text-align: right;">Country :
                    </td>
                    <td>
                        <input type="text" id="txtCountry" ng-model="country" autocomplete="off" />
                    </td>
                </tr>
                <tr>
                    <td colspan="2" style="text-align: center;">
                        <input type="submit" id="btnSubmit" value="Submit" />
                    </td>


                </tr>


            </table>


        </div>
        <hr />
    </form>
    <div class="container" ng-controller="EmpCtrl" data-ng-init="getEmployee()">
        <div>
            <input type="button" id="btnFetch" value="Fetch" ng-click="getEmployee()" />
        </div>
        <table border="1" style="text-align: center; margin-left: 410px;">
            <tr>
                <td>ID
                </td>
                <td>First Name
                </td>
                <td>Last Name
                </td>
                <td>Address
                </td>
                <td>City
                </td>
                <td>Pincode
                </td>
                <td>State
                </td>
                <td>Country
                </td>
                <td>Use 
                     Action
                </td>

            </tr>
            <tr ng-repeat="record in Emp">
                <td>{{record.ID}}
                </td>
                <td>{{record.FirstName}}
                </td>
                <td>{{record.LastName}}
                </td>
                <td>{{record.Address}}
                </td>
                <td>{{record.City}}
                </td>
                <td>{{record.Pincode}}
                </td>
                <td>{{record.State}}
                </td>
                <td>{{record.Country}}
                </td>
                <td><a ng-click="editEmployee(record.ID)">Edit</a></td>
                <td><a ng-click="deleteEmployee(record.ID)">Delete</a></td>
            </tr>
        </table>
    </div>
</body>
</html>

 [WebMethod]
        [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
        public static string InsertEmployee(int empID, string firstName, string lastName, string address, string city, string pincode, string state, string country)
        {
            string connection = @"Data Source=dbpath;Initial Catalog=AngularJS;User Id=sa;Password=sa@123;";
            SqlConnection con = new SqlConnection(connection);
            SqlCommand cmd;
            string msg = "";
            try
            {
                con.Open();
                cmd = con.CreateCommand();
                if (empID == 0)
                {
                    cmd.CommandText = "INSERT INTO Emp_Details(FirstName,LastName,Address,City,Pincode,State,Country) VALUES(@FirstName,@LastName,@Address,@City,@Pincode,@State,@Country)";
                    msg = "Record Inserted Successfully";
                }
                else
                {
                    cmd.CommandText = "update  Emp_Details set FirstName =@FirstName,LastName=@LastName,Address=@Address,City=@City,Pincode=@Pincode,State=@State,Country=@Country where ID=" + empID;
                    msg = "Record updated Successfully";
                }
                cmd.Parameters.AddWithValue("@FirstName", firstName);
                cmd.Parameters.AddWithValue("@LastName", lastName);
                cmd.Parameters.AddWithValue("@Address", address);
                cmd.Parameters.AddWithValue("@City", city);
                cmd.Parameters.AddWithValue("@Pincode", Convert.ToInt32(pincode));
                cmd.Parameters.AddWithValue("@State", state);
                cmd.Parameters.AddWithValue("@Country", country);
                cmd.ExecuteNonQuery();
                return msg;
            }
            catch (Exception)
            {

                throw;
            }
            finally
            {
                if (con.State == ConnectionState.Open)
                {
                    con.Close();
                }

            }
        }

<Cs Code>

DNN Output Image

As you can see in the above image it's not fetching any data it's just printing my field description.

Use ajax to refresh page without reload, and in this pages use POST / GET

There are 3 sides, which I'm using Ajax to avoid having to reload the page to refresh. This 3 side content, and js :

Content:

<ul id="nav">
<li><a href="ajax_adat.php?id=8&epul=0">Adatok</a></li>
<li><a href="piac_vasarlas.php?id=8&epul=0">Kereskedelem</a></li>
<li><a href="piac_egyseg_gyartas.php?id=8&epul=0">Egység gyártás</a></li>

Js:

$(document).ready(function () {

$('ul#nav li a').click(function(){
    var page = $(this).attr('href');
    $('#content').load('../views/' + page );
    return false;
});});

All three pages would like to use POST and GET. For example what i like to use: The egyseg_gyartas.php?id=8&epul=0 look like:

...<input type=\"number\" name=\"v_vesz\" min=\"0\" max=\"".$hany["$v[$i]"]["epitheto"]."\" step=\"1\">...
<form action="<?php echo $_SERVER['PHP_SELF'], '?id=' . $id . '&epul=' . $lenneEpulet . '&Pgyart';?>" method="post">
    <input type="submit" name="egyseg_vasarlas" value="Küldés" style="float: left">
    <input type="Button" value="Vissza" onclick="$:location.href='../views/jatek.php'" style="float: left; margin-left: 10px">
</form>

For example the POST :

if( isset($_POST['egyseg_vasarlas']) )
{
    x = $_GET['v_vesz']
    ..... 
}

So how can i use POST if i use this refreshed pages without reload ? In the POST usually have to change the variables which will build on that page . For example, you can buy a wagon ( game ), and if you bought it , int the POST i need to change, now he cant buy 2 wagon, only 1, and i use php functions in POST, etc... .

Primefaces Command Button Ajax Works Only Once

I have the following command button which enters only once in the saveData method:

<p:commandButton id="saveBtn" 
    value="#{messages['um3.common.label.save']}"            
    actionListener="#{advisorBean.saveData}"            
    disabled="#{advisorBean.disabledSave}">             
    <f:param name="positionId" value="#{advisorBean.positionId}" />
</p:commandButton>

Here is the saveDate method signature: public void saveData().

Also, the page containing the button is inserted into a layout and the button sits in a primefaces panel.

Layout Page:

<h:body>
    <p:layout fullPage="true">
       <p:layoutUnit>
            <ui:insert name="footer">

Button Page:

<ui:define name="footer">
            <p:panel id="footer">
                <p:commandButton id="saveBtn" ...

Could you please advise?

Andrei

Open a particular accordion div after ajax call

I am submitting some values to database through ajax and i want to reload and open a particular accordion div after ajax call.

This is what i was trying and it doesn't work=

'success' : function(data){
                    $("#divId").html(data);

                     $("#divId").load(window.location + "#divId");
                       $("#accordion").accordion("option", "active", $("#activeDiv").index("#accordion div"));

            }

HTML code is here:

<div  id="accordion">
 <h3>heading 1</h3>
 <div id="activeDiv">
   <p>kksksksksk</p>
 </div>
 <h3>heading 2</h3>
 <div id="activeDiv1">
   <p>kksksksksk</p>
 </div>
 <h3>heading 3</h3>
 <div id="activeDiv2">
   <p>kksksksksk</p>
 </div>
</div>

not loading the content of a remote file

I have a file edit.blade.php. I want to load content in a div with load ajax

@if(Auth::check() && Auth::user()->admin)
@section('modal_body')
      @if($errors->any())
        <div class='alert alert-danger'>
            <a href="#" class="close" data-dismiss="alert">&times;</a>
            @foreach($errors->all() as $error)
                {{ $error }} <br/>
            @endforeach
        </div>
        @endif
    {{ Form::open(array('id' =>'formuser-create', 'role' => 'form', 'class' => 'form-horizontal')) }}
            <div class="form-group">
                {{ Form::label('user', 'Nombre de usuario', array('class' => 'col-md-4 control-label')) }}
                <div class="col-md-5">
                    {{ Form::text('user','', array('placeholder' => 'Introduce la contraseña...', 'class' => 'form-control input-md')) }} 
                    <div id="user_error"></div>
                </div>
            </div>
            <div class="form-group">
                {{ Form::label('email', 'Email', array('class' => 'col-md-4 control-label')) }}
                <div class="col-md-5">
                    {{ Form::text('email','', array('placeholder' => 'Introduce el email...', 'class' => 'form-control input-md')) }} 
                    <div id="email_error"></div>
                </div>
            </div>
            <div class="form-group">
                {{ Form::label('es_admin', '¿Es administrador?', array('class' => 'col-md-4 control-label')) }}
                <div class="col-md-5">
                    {{ Form::checkbox('es_admin','1') }}
                </div>
            </div>
@stop

I want to load the content in a div, but not get loading

enter image description here

Here my file where I call load, but I get how response status 404 not found

 var modal_title = $(this).find('.modal-title');
       var modal_body = $(this).find('.modal-body');
       //var modal_footer = $(this).find('.modal-footer');

       switch(accion)
       {
            case 'create':
               modal_title.html('<i class="fa fa-user-plus"></i> Nuevo usuario');   
               break;
            case 'edit':
               modal_title.html('<i class="fa fa-pencil fa-fw"></i> Editar usuario');
               modal_body.load('includes/edit.blade.php');
               break;

The error throwed is:

Failed to load resource: the server responded with a status of 404 (Not Found)