Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7010639
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:01:07+00:00 2026-05-27T22:01:07+00:00

In my Javascript code after the line below: url: ……/Misc-2/Ci-TodoList/index.php/home/jsonAddData, I am getting the

  • 0

In my Javascript code after the line below:

url: ……/Misc-2/Ci-TodoList/index.php/home/jsonAddData,

I am getting the following error:

index.php:13 Uncaught SyntaxError: Unexpected token :

<script type="text/javascript" language="javascript">
$(document).ready(function() {
    $('#add').bind('keypress', function(e) {
        if(e.keyCode == 13){
            $.ajax({
            type: "POST",
            dataType: "JSON",
            url: <?php echo site_url("home/jsonAddData"); ?>,
            data: dataString,
            json: {title_posted: true},
            success: function(data){
            if(data.title_posted == true) { // true means data was successfully posted.
                $("#success").append("Success");
            } else if(data.title_posted == false) { // false means data failed to post.
                $("#success").append('Failure');
            }
          }
       });
    }
});

      }
    });
});
</script>

I’m pretty positive after a few debugging tricks that index.php:13 is referring to my PHP script. One of the things it was doing was saying that when I was loading the url helper, it said that that was causing the error. Then I autoloaded the url helper and now it’s saying line 13 is causing the error, but line 13 is only a mysql select query as you can determine below:

<?php
class home extends CI_Controller {
    function __construct() {
        parent::__construct();
    }
    function index() {
        $data = array();
        $data['lists'] = $this->displayList();
        $this->load->view('home', $data);
    }
    function displayList() {
        $str = '';
        $query = $this->db->query("SELECT * FROM data");
        foreach ($query->result() as $row) {
            $b = '<input name="completed" type="checkbox" />';
            $a = $row->title . "<br>";
            $str .= $b.$a;
        }
        return $str;
    }
    function jsonAddData() {
        if($this->input->is_ajax_request()) {
        header('Content-type:application/json');
        $title = $this->input->post('title');
        $query = $this->db->query("INSERT INTO data (title) VALUES ('$title')");
        if($query) return json_encode(array('title_posted' => true));
        else return json_encode(array('title_posted' => false));
        }
    }
}
?>

Any ideas to why this is happening?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T22:01:08+00:00Added an answer on May 27, 2026 at 10:01 pm

    You are getting JS error so PHP syntax is not the culprit. 🙂

    Wrap <?php echo site_url("home/jsonAddData"); ?> in double quotations (I mean ""). Also you have other syntax errors, proper indenting can save your time in the future.

    Here is the solved version:

    $(document).ready(function() {
        $('#add').bind('keypress', function(e) {
            if(e.keyCode == 13){
                $.ajax({
                    type: "POST",
                    dataType: "JSON",
                    url: "<?php echo site_url("home/jsonAddData"); ?>",
                    data: dataString,
                    json: {title_posted: true},
                    success: function(data){
                        if(data.title_posted == true) { // true means data was successfully posted.
                            $("#success").append("Success");
                        } else if(data.title_posted == false) { // false means data failed to post.
                            $("#success").append('Failure');
                        }
                   }
              });
           }
        });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've seen the following (bizarre) Javascript rounding function in some legacy code. After googling
I know that I can run a line of javascript code after the page
Can anyone tell me how to write javascript code that removes everything after the
I'm collecting latitude and longitude from Mobile Safari with some JavaScript code. After collecting
I have the following JavaScript code to pop up a window in Internet Explorer.
This little line of code here is from a shopping cart: <a href=javascript:; onclick=simpleCart.add(
Using YUICompressor I get the following error from my javascript code: [ERROR] 270:201:missing name
In my JavaScript code, I have to make a line like this (I use
After trying to append some code to a div layer I received the following
The JavaScript code window.print() can print the current HTML page. If I have a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.