Hi,
i need urgent help..
iam working on leave management system(LMS).if the employee apply for the leaves means,one message go to HR inbox (internal application inbox).
iam designing inbox for this..it has two parts(2 coloums).in the first coloumn iam displaying messages with employe name,id nd subject(just like preview of the message)..iam retriving employee name and id,and subject from the database.if the HR click on the particular messages,that message whole content should display in the second coloumn.it should be dynamic.
any idea,any help?how to achive this??

Dani AI

Generated

Brief, practical diagnosis and steps to fix the 404 and show the full message inline.

's alert proves the click handler can read the message id; was right that the server should return the full message. A 404 from the AJAX request almost always means the requested URL is wrong or the server routing/file is not found — not that the POST body is missing. Common culprits: wrong relative path, case-sensitive filename on Linux, .htaccess rewrites, or the file actually living outside the web root.

Quick checklist to narrow it down:

  • Inspect the Network tab: confirm the request URL, method and response code; open that URL directly in a browser to see what the server returns.
  • Remember relative URLs are resolved from the page URL (not the .js file). If unsure, use an absolute path (leading slash) to the PHP endpoint.
  • Check server logs and PHP error log for missing-file messages. Confirm filesystem permissions and exact filename/casing.
  • If switching from form-encoded requests to JSON, the PHP side must read php://input and json_decode() rather than looking only in form fields.
  • Use delegated event binding or data attributes for the preview elements so the id retrieval is robust (store the id as data-msg-id).

Example pattern (JS uses fetch; PHP reads JSON). Adjust paths to match the site structure.

// attach to a container and read data-msg-id from each preview
document.querySelector('#inboxList').addEventListener('click', function(e) {
  const preview = e.target.closest('.preview');
  if (!preview) return;
  const id = preview.dataset.msgId;
  fetch('/api/get-message.php', {
    method: 'POST',
    headers: {'Content-Type':'application/json'},
    body: JSON.stringify({ id: id })
  })
  .then(r => { if (!r.ok) throw new Error(r.status); return r.json(); })
  .then(json => { document.getElementById('messagePane').innerHTML = json.body || ''; })
  .catch(console.error);
});
<?php
header('Content-Type: application/json');
$input = json_decode(file_get_contents('php://input'), true);
$id = isset($input['id']) ? (int)$input['id'] : 0;
if (!$id) { http_response_code(400); echo json_encode(['error'=>'missing id']); exit; }
// fetch message with prepared statements, then:
echo json_encode(['body'=>$messageBody]);
?>

Security notes: validate/cast the id, use prepared statements for DB access, and return clear HTTP status codes. A 404 means "file not found"; a 500 means a server error — use the Network tab and server logs together to find which.

Recommended Answers

All 4 Replies

If you are only pulling through the name and subject initially (and ID presumably) then when the preview is clicked on you do another database query to get the rest of the message information using the ID as the identifier. And then display that in the seond area in pretty much the same way you displayed the preview.

my problem is how to pass jS variable from .js file to .php file.
means if i click on the preveiew of message, the message id is storing in external jS file
inbox.js

  $( ".sender" ).on("click",function()
    {
    var test=(($("input[name=sender]").val()));
    var id=$(this).parent().attr('id');
    });

now i want to send that variable id to .php file
( if i click on the preveiew of message,respective content should be display on the right side)

Look into jquery http.post method. It lets you make an AJAX call to a URL you specify and pass in data.
The PHP script reads in the $_POST variables and you're all set to do your database query

Any help?

inbox.js

$( ".sender" ).on("click",function()
        {
        var test=(($("input[name=sender]").val()));
        var id=$(this).parent().attr('id');
    alert(id);//its working fine ,iam getting the id here


    $.ajax({
                        type:'post',
                        url: "inbox.php",
                        data:{
                            msg_id:id

                            },

                        success: function(data){

                        alert(data);

                      }
                });



        });

inbox.php

<?php $msg_id=$_POST['msg_id'];
?>

iam not getting the $msg_id ,
getting 404 server response error

any help??

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.