adly adly - 5 months ago 8
Javascript Question

CSS an javascript gone after I click on a button

Currently I have a problem on all the pages.The page contains a form with a submit button and a table that contains buttons.The problem is whenever I click on edit button from

the table
the
css
and
javascript
are gone.

Here is jascript code

<script type="text/javascript">
$(document).ready(function() {
var table = $('#datatable').dataTable();
var tableTools = new $.fn.dataTable.TableTools(table, {
'aButtons' : [ ],
'sSwfPath' : 'js/copy_csv_xls_pdf.swf'

});

$(tableTools.fnContainer()).insertBefore('#datatable_wrapper');
});
</script>


The table

<table id="datatable" class="hover" >
<thead>

<tr>
<th width="80">Poll ID</th>
<th width="120">Poll Name</th>
<th width="120">Poll Description</th>
<th width="120">poll publisher</th>


<th width="60">Edit</th>
<th width="60">Delete</th>
<th width="60">Voter</th>
<th width="60">Afficher courbe</th>

</tr>
</thead>
<tfoot>

<tr>
<th width="80">Poll ID</th>
<th width="120">Poll Name</th>
<th width="120">Poll Description</th>
<th width="120">poll publisher</th>


<th width="60">Edit</th>
<th width="60">Delete</th>
<th width="60">Voter</th>
<th width="60">Afficher Courbe</th>

</tr>
</tfoot>
<c:forEach items="${listpolls}" var="poll">
<tbody>

<tr>
<td>${poll.id_poll}</td>
<td>${poll.titre}</td>
<td>${poll.description}</td>
<td>${poll.emp_login}</td>



<td><a href="<c:url value='/poll/edit/${poll.id_poll}' />">Edit</a></td>
<td><a href="<c:url value='/poll/remove/${poll.id_poll}' />">Delete</a></td>
<td><a href="<c:url value='/poll/voter/${poll.id_poll}' />">Vote</a></td>
<td><a href="<c:url value='/sa/${poll.id_poll}' />">Afficher courbe</a></td>

</tr>
</c:forEach>
</tbody>

</table>


Here is an picture of the table before i click on edit.

enter image description here

And now

enter image description here

As you can see css and javascipt code are both gone.

What am I doing wrong here? Any help is much appreciated.

Answer

Problem is the /poll/edit/... etc. in link's href. Even if redirected, browser still thinks you're in different directory from where relative paths to your styles & scripts won't work.

Specify base directory for all links on page:
<base href="http://www.domain.com/somebasedir/" />

Then regardless of the redirection, for example this stylesheet:
<link rel="stylesheet" type="text/css" href="path/style.css" />

should always be looked for in:
/somebasedir/path/style.css

Comments