Welcome Guest, Not a member yet? Register   Sign In
How to get text box value in ajax jquery using codeigniter
#1

[eluser]Unknown[/eluser]
my code is

in C:\wamp\www\books\application\views\view_login.php

<html>
<head>
[removed][removed]
[removed]
$(document).ready(function()
{
$('#login-button').click(function()
{
var username = $("#username").val();
var password=$("#passord").val();
var dataString = 'username='+username + ' ' + 'password='+password;
alert(username);
$.ajax({
type: "POST",
url: "http://localhost/edit/index.php/login/ajax/"+dataString,
data: dataString,
success: function(msg)
{
$("#status").html(dataString);

}
});
});
});

</script>

</head>
<form method="post">
username: <input type="text" name="username" id="username" /> <br />
password: <input type="passord" name="passord" id="passord" />
<input type="button" name="login" value="submit" id="login-button"/>
</form>
<div id="status"></div>
</html>

---------------------------------------------------------------------------

in C:\\wamp\\www\\books\\application\\controllers\\login.php

<?
class Login extends CI_Controller
{
function Login()
{
parent::__construct();
}

public function ajax()
{
$this->load->view('view_login');
echo '=>'.$this->input->post('username');
echo '=>'.@$_GET['username'];
}
}
?>

i can't get text box value in Controller. How can i get it please help me


#2

[eluser]TheFuzzy0ne[/eluser]
Welcome to the CodeIgniter forums!

In future, please wrap your code in [code]code tags[/code]. It makes your code easier to read. Smile

[quote]
my code is

in C:\wamp\www\books\application\views\view_login.php
Code:
<html>
<head>
<$cript type="text/javascript">
    $(document).ready(function()
    {
        $('#login-button').click(function()
        {
            var username = $("#username").val();
            var password=$("#passord").val();
            var dataString = 'username='+username + ' ' + 'password='+password;
            alert(username);
            $.ajax({
                type: "POST",
                url: "http://localhost/edit/index.php/login/ajax/"+dataString,
                data: dataString,
                success: function(msg)
                {
                    $("#status").html(dataString);
                }
            });
        });  
    });
&lt;/$cript&gt;

&lt;/head&gt;
&lt;form method="post"&gt;
    username: &lt;input type="text" name="username" id="username" /&gt; &lt;br /&gt;
    password: &lt;input type="passord" name="passord" id="passord" /&gt;
    &lt;input type=“button” name="login" value="submit" id="login-button"/&gt;
&lt;/form&gt;
&lt;div id="status"&gt;&lt;/div&gt;
&lt;/html&gt;
—————————————————————————————————————-

in C:\\wamp\\www\\books\\application\\controllers\\login.php

Code:
&lt;?
class Login extends CI_Controller
{
    function Login()
    {
        parent::__construct();
    }

    public function ajax()
    {
        $this-&gt;load-&gt;view('view_login');
        echo '=>'.$this->input->post('username');
        echo '=>'.@$_GET['username'];  
    }
}
?&gt;
i can’t get text box value in Controller. How can i get it please help me
#3

[eluser]TheFuzzy0ne[/eluser]
Your HTML is invalid. You have no body tags, you're missing attributes, you have no doctype, no character encoding specified, no page title, and your submit button is the wrong type.

You submit button will work better like this:
Code:
&lt;input type=“submit” name="login" value="submit" id="login-button" /&gt;

You should really consider [url="http://validator.w3.org/"]validating your HTML[/url]. The standards exist for a reason. Some browsers won't display your code correctly (if at all).




Theme © iAndrew 2016 - Forum software by © MyBB