mercredi 6 mai 2015

Send value from controller with ajax Codeigniter

i have javascript like this

$(document).ready(function(){
    $("input[type='checkbox']").change(function(){
        var menu_id = this.value;
        if(this.checked) var statusvalue = "On";
        else var statusvalue = "Off";
        $.ajax({
            type    : "POST",
            url     : "admin/menu/editstatus",
            data    : "id=" + menu_id + "&value=" + statusvalue,
            success : function(data){
                $("#testing").html(data);
            }
        });
    });
});

and my controller named menu and have function editstatus()

public function editstatus()
{
    $data = "asd";
    echo $data;
}

but textbox with id testing not writen anything

Saving data with ajax and json

I am working on a project that I didn't start and I have an input that is function is to save the data to the data base. The input leaves to this function (SaveData) and it isn't working. I really don't understand much from ajax and json, so could anyone please see what's wrong with this?

The function is this:

 function SaveData() {
     var columns = [];

     $("#FeaturedContent_m_visible_cols li").each(function (i, elem) {
        columns[i] = $(elem).attr("colid");
     });

     $.ajax({
        async: false,
        type: "POST",
        url: "http://ift.tt/1EPQ0gY",
        data: "{ 'jsonData': [" + JSON.stringify(columns) + "] }",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (response) {
        },
        error: function (response) {
           alert(jQuery.parseJSON(response.responseText).Message);
        }
     });

The SaveConfiguration method is this:

[System.Web.Services.WebMethod]
 [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
  public static string SaveConfiguration(dynamic jsonData)
{
 Object[] column = (Object[])jsonData[0];
  string   col_id;
  int      i;

  for (i=0; i<column.Length; i++) {
     col_id = (string)column[i];
  }

  SaveTableConfiguration();

  return "";
  }

And the SaveTableConfiguration:

 public void SaveTableConfiguration(int list_id, List<TableHeader> lista)
  {
    int           i;
    TableHeader   row;
    SetListConfig set_lconfig = new SetListConfig(m_connection, m_language);

set_lconfig.LoadRecordset("LC_LISTID=" + list_id.ToString(),    m_transaction);
     while (!set_lconfig.IsEOF()) {
        set_lconfig.m_LC_EDITABLE = 0;
        set_lconfig.Update();

        set_lconfig.MoveNext();
     }

     for (i=0; i<lista.Count;i++) {
        row=lista[i];

set_lconfig.LoadRecordset("LC_LISTID=" + list_id.ToString() + " AND                LC_COLTBL='" + row.header_col + "'", m_transaction);
        if (set_lconfig.IsEOF()) {
           set_lconfig.m_LC_EDITABLE = 1;
           set_lconfig.m_LC_ORDER = i+1;
           set_lconfig.Update();
        }
     }
  }

Thanks Once more! =)

How to pass mysql result as as jSON via ajax

I'm not sure how to pass the result of mysql query into html page via ajax JSON. ajax2.php

$statement = $pdo->prepare("SELECT * FROM posts WHERE subid IN (:key2) AND Poscode=:postcode2");
    $statement->execute(array(':key2' => $key2,':postcode2'=>$postcode));
 // $row = $statement->fetchAll(PDO::FETCH_ASSOC);
 while( $row = $statement->fetch())
 {
     echo $row['Name'];//How to show this in the html page?
      echo $row['PostUUID'];//How to show this in the html page?
      $row2[]=$row;
 }
    echo json_encode($row2);

How to pass the above query result to display in the html page via ajax below?

my ajax

$("form").on("submit",function() {

    var data = {
      "action": "test"
    };
    data = $(this).serialize() + "&" + $.param(data);
    $.ajax({
      type: "POST",
      dataType: "json",
      url: "ajax2.php", //Relative or absolute path to response.php file
      data: data,
      success: function(data) {
          //how to retrieve the php mysql result here?
        console.log(data);// this shows nothing in console,I wonder why?
      }
    });
    return false;

});

JQuery ajax post function is executed at the end of javascript

i have a problem with validating if the username is already taken. I am trying to find out if the username already exists using the "post" method of jquery. But when executing this function, the script is alway jumping to the end of the function and is doing the rest of the script first before executing the "post" command. Could you please review my code and help me?

$("#submit").click(function () {

    var username = document.getElementById("username").value;
    var email = document.getElementById("email").value;
    var passwort = document.getElementById("passwort").value;
    var passwort2 = document.getElementById("passwort2").value;
    var validate = false;

    checkUsername();

    if (validate == true) {
        $.post("Login/register.php", {

            username: username,
            email: email,
            passwort: passwort,
            passwort2: passwort2,
        }, function (info) {
            $("#errorBox").empty();
            $("#errorBox").html(info);
        });

    } else {
        $('#register').submit(function () {
            return false;
        });
    }

    function checkUsername() {
        username = document.getElementById("username").value;
        // username = replaceUmlauts(username);
        if (username.length > 0) {
            document.getElementById("username").style.borderColor = "";
            // document.getElementById("errorBox").innerHTML =
            // "";
            validate = true;
            checkAvailability();
            return false;
        } else {
            document.getElementById("username").style.borderColor = "red";
            document.getElementById("errorBox").innerHTML = "Username muss länger als ein Zeichen sein";
            // alert('Username must be longer than one sign');
            validate = false;
            return false;
        }
    }

    function checkAvailability() {
        $.post(
            "Login/checkusername.php", {
                username: username
            },
            function (result) {
                // if the result is 1
                if (result == 1) {
                    // show that the username is
                    // available
                    document
                        .getElementById("errorBox").innerHTML = "";
                    return false;
                } else {
                    // show that the username is NOT
                    // available
                    document
                        .getElementById("errorBox").innerHTML = "Username nicht verfuegbar";
                    document
                        .getElementById("username").style.borderColor = "red";
                    validate = false;
                    return false;
                }
            });

    }
    return false;

});

how to display image after upload in Symfony2

i have a register form (based on FOSUserBundle) in my Symfony2 application. A user can upload an avatar for its profile before submitting the form. I want display its picture just after upload in ajax . How can i do that?

Best framework to develop java web based application

I want to develop a social networking site like facebook using java technology. But i am confused that which framework i should use because there are many frameworks in java.

I want to develop in few time and fast, maintainable application which will held a lots of data.And i will use javascript and ajax in that application.

So please suggest me the best framework in java with their advantages and drawbacks.And also suggest me the best database with that framework.

Thanx in advance

AJAX function is not working by scroll

Using AJAX for endless scroll. Content loads only first time, but does't load by scroll.

What is wrong?

jQuery:

function loadFeed() {
    $.ajax({
        url: 'loadmore.php',
        dataType: 'html',
        success: function (data) {
            $("#posts").append('<div class="havanagila"></div>');
            $('#posts').html(data);
        }
    });
}

loadFeed();
$(window).scroll(function () {
    var windowScroll = $(window).scrollTop();
    var windowHeight = $(window).height();
    var documentHeight = $(document).height();

    if ((windowScroll + windowHeight) == documentHeight) {
        loadFeed();
    }
});

loadmore.php:

<?php 
session_start();

if ( isset( $_SESSION['login'] ) ) {

    $login    = $_SESSION['login'];
    $id=$_SESSION['id'];

    $username="root";
    $password="root";
    $hostname = "localhost";
    $dbname= "kotik";


    function testdb_connect ($hostname, $username, $password){
        $dbh = new PDO("mysql:host=$hostname;dbname=kotik", $username, $password);
        return $dbh;
    }


    try {
        $dbh = testdb_connect ($hostname, $username, $password);

    } catch(PDOException $e) {
        echo $e->getMessage();
    }

}

?>

<?php                                                              

$title_select_query= $dbh -> prepare("SELECT title FROM books WHERE id = :id ORDER BY date DESC");
$title_select_query ->execute(array(':id' => $id));
$title_select_query_result = $title_select_query->fetchColumn(); 
echo($title_select_query_result);

$title_select_query_result = $title_select_query->fetchColumn(); 
echo($title_select_query_result);

$title_select_query_result = $title_select_query->fetchColumn(); 
echo($title_select_query_result);

$title_select_query_result = $title_select_query->fetchColumn(); 
echo($title_select_query_result);

$title_select_query_result = $title_select_query->fetchColumn(); 
echo($title_select_query_result);

?>