Welcome Guest, Not a member yet? Register   Sign In
[SOLVED] jQuery not seeing my controller function
#1

[eluser]Unknown[/eluser]
Thank you for your help. It is appreciated, greatly.

I have watched several videos and followed the tutes on them. They all seem to do the same process and fail in the same place. What am I missing?

I have a simple example here a controller, a view, and a javascript file. I want the javascript to call the "Demo" controller's function called "process" when the submit button is clicked, but Firebug/Firefox and Chrome return the following error:

Network error: 404 Not FOund - http://localhost:8060/ci_site/demo/process"

Here's my controller:
<?php

class Demo extends CI_Controller {

function Demo() {

parent::__construct();
}

function index() {

$this->load->view('public2/testme');
}

function process() {
$item = trim($this->input->post('item'));
$array = array('result' => $item);
echo json_encode($array);
}

}



Here's my view: Of course in the "Removed" lines those are calls to jQuery and my js file. That is working okay.
<html>
<head>
<title>MY TEST!!</title>
Quote: [removed][removed]
[removed][removed]
</head>
<body>
<p>
<label for="item">Item Name</label>
<br/>
&lt;input type="text" id="item" name="item" /&gt;
</p>
<p>
&lt;input type="submit" name="submit" id="submit_item" value="Submit Item" /&gt;
</p>
&lt;/body&gt;
&lt;/html&gt;



Here's my javascript file:

$(document).ready(function() {

$('#submit_item').click(function() {

var item = $('#item').val();

$.post("demo/process", { 'item' : item },
function(data){
alert(data.result);
}, "json");
});
});




Theme © iAndrew 2016 - Forum software by © MyBB