Reputation: 5758
I'm performing an Ajax
request to a php
file called save_tags.php
this is the content of the file:
$id = $_POST['id'];
$name = $_POST['name'];
$type = $_POST['type'];
$tags = json_decode(stripslashes($_POST['tags'])); //Should be an Array but is a String...
$removeTags = json_decode(stripslashes($_POST['removeTags']));
//Type can be company, contact, column, supplement, programme.
if($type == 'company'){
$tagObject = new DirectoryCompany($id);
}elseif($type == 'contact'){
$tagObject = new DirectoryContact($id);
}elseif($type == 'column'){
$tagObject = new Column($id);
}elseif($type == 'supplement'){
$tagObject = new Supplement($id);
}elseif($type == 'programme'){
$tagObject = new Programme($id);
}elseif($type == 'list'){
$tagObject = new DirectoryContactList($id);
}
//Add and Remove Tags by looping through the Arrays.
foreach($tags as $tag){
$tagObject->addTag($tag, $id);
}
foreach($removeTags as $tag){
$tagObject->deleteTag($tag, $id);
}
//Get the tags associated with the object
$tagarray = $tagObject->getTags($id);
// Add Tags to All contacts on the list
$tagObject->getAllcontactsAndAddTags($id);
//Build HTML output
$output = "<ul>";
foreach($tagarray as $tag){
$output .= "<li>". $tag .'<a href="#">[X]</a>'."</li>";
}
$output .= "</ul>";
echo $output;
?>
The purpose of the file is to apply the tags a user has checked and apply them to the object being worked on. Currently the above code is working, as in the tags are being applied and saved. however what is not working is that the $output
variable is not being echoed
and I can't figure out why.
Also when I check my console via the browser window I can see that there was a 500
error when requesting the file.
I'd appreciate any help.
Upvotes: 1
Views: 88
Reputation: 543
500 errors usually means that there's something wrong with your php code. Make sure that the code doesn't error out. Try to go to it in your browser and confirm that there are no errors.
Upvotes: 1
Reputation: 3172
<ul>
this is tag html, check source page
and check alert(data)
$.ajax({
type: 'POST',
url: 'url',
data: { },
success: function(data) {alert(data)}
});
$output = "<ul>";
foreach($tagarray as $tag){
$output .= "<li>". $tag .'<a href="#">[X]</a>'."</li>";
}
$output .= "</ul>";
echo $output;
if $tagarray is null echo = <ul></ul>
invisible on the page
Upvotes: 1
Reputation: 439
First, try to put a few var_dumps here and there to see if you data is correct. An statuscode 500 means that there was most likely a fatal error in your script. This can be either in this php file or in one of your classes. Most likely you will find the answer in a few minutes. To check if your script even works, try to echo some simple like "test" and comment everything else.
Upvotes: 0