The forum of the forums
Would you like to react to this message? Create an account in a few clicks or log in to continue.

[Slightly difficult question] how to modify theme without page refresh

3 posters

Go down

Solved [Slightly difficult question] how to modify theme without page refresh

Post by developer.ryan September 1st 2015, 2:07 pm

Hi everyone

I have a question a little difficult

How to modify the title of the topic without refresh page
any that i edit the title in the same subject without departing from the same page


Last edited by developer.ryan on September 2nd 2015, 7:49 pm; edited 1 time in total
developer.ryan
developer.ryan
Forumember

Posts : 98
Reputation : 6
Language : English,Chinese,Italian,French
Location : The doors of development

http://javascript:self.close()

Back to top Go down

Solved Re: [Slightly difficult question] how to modify theme without page refresh

Post by Ange Tuteur September 1st 2015, 2:32 pm

To do anything like that, you'd need to utilize AJAX. This is an example of how you could update the content of a post :
Code:
$.post('/post', {
  subject : 'Topic title',
  message : 'Message content',
  mode : 'editpost',
  p : 'post_id',
  post : 1
});

You'd need to replace post_id with a valid post identifier. ( e.g. 1, 2, 3.. ) Furthermore, for this example to work you'd need to disable the security option "disallow unofficial forms to post on the forum" via General > Security.

If you want to get past that you need to first send a GET request to return the form data. For example :
Code:
$.get('/post?mode=editpost&p=1', function(data) {
  var form = $('form[name="post"]', data).serialize(); // get the serialized form data
  console.log(form); // view data in the console
});

You can then proceed to manipulate the data as needed and then submit a POST request to update the data.
Ange Tuteur
Ange Tuteur
Forumaster

Male Posts : 13207
Reputation : 3000
Language : English & 日本語
Location : Pennsylvania

https://fmdesign.forumotion.com

Back to top Go down

Solved Re: [Slightly difficult question] how to modify theme without page refresh

Post by developer.ryan September 1st 2015, 8:01 pm

Thank you, but nothing happens

In my profile I can modify date of birth

Example

[Slightly difficult question] how to modify theme without page refresh Newq10

i want same this
developer.ryan
developer.ryan
Forumember

Posts : 98
Reputation : 6
Language : English,Chinese,Italian,French
Location : The doors of development

http://javascript:self.close()

Back to top Go down

Solved Re: [Slightly difficult question] how to modify theme without page refresh

Post by Ange Tuteur September 1st 2015, 8:17 pm

I'll need more information before I can do anything. Such as the URL of your forum, that way I have an understanding of the document.
Ange Tuteur
Ange Tuteur
Forumaster

Male Posts : 13207
Reputation : 3000
Language : English & 日本語
Location : Pennsylvania

https://fmdesign.forumotion.com

Back to top Go down

Solved Re: [Slightly difficult question] how to modify theme without page refresh

Post by developer.ryan September 1st 2015, 11:56 pm

developer.ryan
developer.ryan
Forumember

Posts : 98
Reputation : 6
Language : English,Chinese,Italian,French
Location : The doors of development

http://javascript:self.close()

Back to top Go down

Solved Re: [Slightly difficult question] how to modify theme without page refresh

Post by Ange Tuteur September 2nd 2015, 12:27 pm

Thanks, version phpbb3 will be easy to work with.

Go to Modules > JavaScript codes management and Create a new script with the following settings.

Placement : In the topics
Code:
$(function() {
  var h2 = $('h2.topic-title')[0],
      a = document.createElement('A');

  // edit button attributes
  a.innerHTML = '&nbsp;<img src="http://i21.servimg.com/u/f21/18/21/60/73/10053510.png" alt="Edit Title"/>';
  a.title = 'Edit topic title';
  a.className = 'editTitle';
  a.href = '#';

  // edit function
  a.onclick = function(e) {
    var t = this;
    e.preventDefault();
   
    $.get('/post?mode=editpost&p=' + t.previousSibling.href.replace(/.*?#(\d+)/, '$1'), function(d) {
      var form = $('form[name="post"]', d)[0],
          newTitle = prompt('Please insert a new title for this topic.', form.subject.value);

      if (newTitle) {
        form.subject.value = newTitle;

        $.post('/post', $(form).serialize() + '&post=1', function(data) {
          $('h2.topic-title a[href^="/t"]').text(newTitle);
        });
      }
    });
  };

  if (h2 && /mode=editpost/.test(h2.previousSibling.innerHTML)) h2.appendChild(a);
  'par ange tuteur';
});

That will add a edit button next to the topic title of the first post. So it works correctly on all pages of a topic I'd recommend enabling the following option.

General > Messages > Config > Always show the first post in the topics : Yes
Ange Tuteur
Ange Tuteur
Forumaster

Male Posts : 13207
Reputation : 3000
Language : English & 日本語
Location : Pennsylvania

https://fmdesign.forumotion.com

Back to top Go down

Solved Re: [Slightly difficult question] how to modify theme without page refresh

Post by developer.ryan September 2nd 2015, 7:48 pm

Wow this is awesome king  

it works for me without any problem

Thank you very much. :rose:
developer.ryan
developer.ryan
Forumember

Posts : 98
Reputation : 6
Language : English,Chinese,Italian,French
Location : The doors of development

http://javascript:self.close()

Back to top Go down

Solved Re: [Slightly difficult question] how to modify theme without page refresh

Post by SLGray September 2nd 2015, 8:47 pm

Topic solved and archived


[Slightly difficult question] how to modify theme without page refresh Slgray10

When your topic has been solved, ensure you mark the topic solved.
Never post your email in public.
SLGray
SLGray
Administrator
Administrator

Male Posts : 51583
Reputation : 3526
Language : English
Location : United States

https://forumsclub.com/gc/128-link-directory/

Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum