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 6116975
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:16:03+00:00 2026-05-23T15:16:03+00:00

I’m calling a php function from my $.ajax call to add a new item

  • 0

I’m calling a php function from my $.ajax call to add a new item to the database. The php function echos a comma separated list of values which I want to use in my ajax success function.
The problem is that the data from the ajax success function seems to have some extra, unwanted data appended to the front of the return string and I have no idea where this comes from!

Here’s the php function:

function add_event_role()
{           
        //validated by jquery already
        $newID = $this->Event_model->insert_event_role(
            $this->input->post('roleEventType'),
            $this->input->post('roleName'),
            $this->input->post('roleRate'));

        //create return value for ajax of id,name of event type
        $retStr = $newID . ',' . $this->get_event_type_name($this->input->post('roleEventType'));

        log_message('error','retStr=' . $retStr);

        echo $retStr; //to send back to ajax call
        return $newID;
}

And here is the jquery that calls this:

   //set form data into a variable
        var dataString = 'roleEventType='+ typeId+'&roleName='+name+'&roleRate='+rate;

        $.ajax({
            type:"POST",
            url:"<?php echo site_url('settings/add_event_role'); ?>",
            data: dataString,
            cache: false,
            success:function(data)
            {
                                    //split the return from add_event_role (it's: id,name)
                                    var splitArr = data.split(',');                                        
                        //message user 
                $.jGrowl("New event role added!", { header: 'Success' });
                //reload event roles to show new event role
                var newRow = "<tr><td>"+splitArr[1]+ "</td><td>"+name+"</td><td>"+rate+"</td><td><a href=\"edit\" id=\"" +splitArr[0]+"\"  class=\"editEventRole\">Edit</a> / <a href=\"delete\" id=\"" +splitArr[0]+"\"  class=\"deleteEventRole\">Delete</a></td></tr>";
                $("#eventRoleList").append(newRow);
                //clear add event form
                //...
            }

        });

As an example: The php function ends up creating the string “12,role” and echos that. By the time it reaches the success function it now reads: “role12,role”. Anyone know why the name is being appended? I have a feeling it’s something really simple but right now I can’t see it for looking at it so any help much appreciated! 🙂

UPDATE:

Thanks to help from Val & Jonathan Kuhn I tracked the problem back to a stray call to “echo” in the function: get_event_type_name which was appending the name onto the following echo.

Perhaps this question should be deleted as the error isn’t truly related to Jquery/Ajax after all?

  • 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-23T15:16:04+00:00Added an answer on May 23, 2026 at 3:16 pm

    Thanks to help from Val & Jonathan Kuhn I tracked the problem back to a stray call to “echo” in the function: get_event_type_name which was appending the name onto the following echo.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I want to count how many characters a certain string has in PHP, but
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a bunch of posts stored in text files formatted in yaml/textile (from
I have a text area in my form which accepts all possible characters from
Seemingly simple, but I cannot find anything relevant on the web. What is the

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.