3

I want to add a notification box on my navigation bar. so when I click on a new notification div I want to show my modal with my notification text and here I used the following ajax function but it can't show me the modal text .

function viewPost(IDnotif){
  var notifId = IDnotif;

  var data = "id="+ notifId;
       $.ajax({
             type: "post",  // Request method: post, get
             url: base_url + "/icicpermis/notifications/getNotification/"+notifId,
             data: data,
             success: function(response) { 

                        document.getElementById("myModal").style.display = "block";

                        document.getElementById("titre").text('New notification ');

                           },
                           error:function (XMLHttpRequest, textStatus, errorThrown) {
                                  alert(textStatus);
                           }
          });
          return false;
}

 </script>

and that's my modal :

<div id="myModal" class="modal">

<!-- Modal content -->
<div class="modal-content" id="content">
    <span class="close">x</span>

    <p id='titre'>Nouvelle notification  </p>
</div>

</div>
Afaf
  • 654
  • 1
  • 5
  • 17
  • Any error in console? – Poonam Nov 15 '16 at 09:19
  • @Poonam There is no error in the console – Afaf Nov 15 '16 at 09:21
  • And why this `return false;` after ajax call? – Poonam Nov 15 '16 at 09:22
  • @Poonam When I removed it i got the following error Uncaught TypeError: document.getElementById(...).text is not a function(…) so I dont know how can I set the content text – Afaf Nov 15 '16 at 09:24
  • @Poonam Still got the same error Uncaught TypeError: document.getElementById(...).html is not a function(…) – Afaf Nov 15 '16 at 09:28
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/128139/discussion-between-poonam-and-afaf). – Poonam Nov 15 '16 at 09:28
  • 1
    Use `document.getElementById("titre").innerHTML = "New notification";` – Poonam Nov 15 '16 at 09:49
  • Simple google search gives [this](http://stackoverflow.com/questions/13183630/how-to-open-a-bootstrap-modal-window-using-jquery). Consider learning jquery a bit. – skywalker Nov 15 '16 at 10:07

1 Answers1

2

In javascript .text() will not work. You have to change the html of #titre

So, In javascript use innerHTML,

document.getElementById("titre").innerHTML = "New notification";

You can use jQuery too

$('#titre').html('New notification');

Remove return false; after ajax call because it will hide the errors.

Poonam
  • 549
  • 4
  • 15