Question

I have searched and tried all the possible ways in here but it didn't fix my problem. then I decided to ask the question. I have a HTML/PHP page that has list of teams and there is a button to update the team name. I am trying to edit the team name without refreshing the page. here is my HTML/PHP:

<input id="team_name_input_field_<?php echo $teamID; ?>" type="text" value="<?php echo $team_name; ?>" style="display:none;">
<input id="team_name_update_button_<?php echo $teamID; ?>" type="button" value="Update" style="display:none;" onClick="updateTeamName(<?php echo $teamID; ?>);">

so onclick of the update button, I am sending the $teamID to my jquery function. here is my jquery:

function updateTeamName(moo)
{
    var name = $("#team_name_input_field_" + moo).val();

    if($.trim(name) != '' && $.trim(name) != 'N/A')
    {
        $.post('add_team_name.php', {name: name}, function(data){
            alert(data);//this is not working 
        });
        alert(moo);//this is working
    }

    else
    {
        alert("enter something please");
    }
}

So moo is the teamID and I am taking the team_name as well and storing it in the name variable. and there is add_team_name.php that is responsible to add the name. but I want to first test if I can get data from add_team_name.php. here is add_team_name.php:

<?PHP

echo "hahahahaha";

?>

I am just echoing "hahahaha" in add_team_name.php and I am alerting the data in the jquery. but nothing is getting alerted. Then I added another alert(moo); after the jquery post and that is alerting moo. so the problem is with my post I think. because I have to be able to get the "hahahahaha" when I alert data. Thanks in advance.

note: my php/html page is in the main directory and the jquery file and add_team_name.php are in the js folder.

Was it helpful?

Solution

So, the problem is with file locations. Php script was put in /js/ directory with a .js file from which request was made, instead of root where was the html/php page including that .js

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top