FM Design
Would you like to react to this message? Create an account in a few clicks or log in to continue.

IMPORTANT

FM Design is in read-only mode, please click here for more information.

Latest topics
» Forumactif Edge - Releases
by Ange Tuteur Tue 03 Sep 2019, 11:49

» GIFActif - Giphy Button for the Editor
by Ange Tuteur Wed 08 May 2019, 17:21

» Forum Closure
by Ange Tuteur Mon 01 Jan 2018, 01:28

» Chit Chat Thread
by Valoish Sun 31 Dec 2017, 19:15

» Font/Text background color.
by Valoish Sun 31 Dec 2017, 19:11

» Forumactif Messenger - Instant Message Application for Forumotion
by Wolfuryo Sun 31 Dec 2017, 18:24

» [GAME] Count to One Million!
by brandon_g Fri 29 Dec 2017, 18:58

» Post Cards
by manikbiradar Wed 20 Dec 2017, 07:50

» [GAME] Countdown from 200,000
by Valoish Wed 13 Dec 2017, 23:22

» GeekPolice Tech Support Forums - GeekPolice.net
by Dr Jay Mon 11 Dec 2017, 19:12

» Asking about some plugin for Forumotion
by Dr Jay Mon 11 Dec 2017, 19:10

» [GAME] What are you thinking right now?
by Van-Helsing Sat 09 Dec 2017, 14:51

» Widget : Similar topics
by ranbac Wed 06 Dec 2017, 18:11

» Change the Background of the Forum and put an image and how to make prefixs?
by Clement Wed 06 Dec 2017, 15:19

» Hello from Western Australia
by SarkZKalie Wed 06 Dec 2017, 05:34

Recent Tutorials
Top posting users this month

Who is online?
In total there are 16 users online :: 0 Registered, 0 Hidden and 16 Guests :: 1 Bot

None

[ View the whole list ]


Most users ever online was 515 on Tue 14 Sep 2021, 15:24

[SOLVED] Using ajax to modify user profile

View previous topic View next topic Go down

Wolfuryo
Wolfuryo

Gender : Male
Posts : 256
Points : 3597
Reputation : 81
Language : Romanian and English
Browser : Browser : Mozilla Firefox Forum Version : Forum Version : Other

PostWolfuryo Sun 08 May 2016, 11:27

Hello,

I'd like to know if there is any way to ajax edit users profiles.
Example:I am user 1 and I want to modify user's 2 profile without going to his profile, but clicking a button.

P.S.:I need this for a warning system. Smile

Tagging @Ange Tuteur
Ange Tuteur
Ange Tuteur
Administrator
Gender : Male
Posts : 4741
Points : 12043
Reputation : 2375
Location : Pennsylvania
Language : EN, JA, FR
Browser : Browser : Brave Forum Version : Forum Version : Forumactif Edge
https://sethclydesdale.github.io/ https://twitter.com/sethc1995

PostAnge Tuteur Sun 08 May 2016, 11:55

@Andrei34 here's a method I wrote awhile back for updating the profile fields via AJAX. It's actually a modified version of how they're already updated when editing fields via your profile.

Install this script in all the pages :
Code:
$.getScript('http://illiweb.com/rs3/25/frm/jquery/json/jquery.json-1.3.min.js', function() {
  window.$updateField = function(o, callback) {
    var c = new Array(),
        admin = $('a[href^="/admin/index.forum"]')[0],
        logout = document.getElementById('logout');

    c.push(new Array(o.name, o.value));
   
    $.post('/ajax_profile.forum?jsoncallback=?', {
          id : o.id.substring(8, o.id.length),
        user : o.user_id,
      active : '1',
      content : $.toJSON(c),
          tid : admin ? admin.href.replace(/.*?tid=(.*)/,'$1') : logout ? logout.href.replace(/.*?tid=(.*?)&.*/,'$1') : ''
    }, function(d) {
      callback && callback(d);
    }, 'json');
  };
  'par ange tuteur';
});


After that you'll be able to do this :
Code:
$updateField({
      id : 'field_id3',
    name : 'profile_field_8_3',
  user_id : 1,
    value : 0
}, function(d) {
  console.log(d); // log return data
});

It takes 4 values :
id : The id of the field. e.g. #field_id3
name : The name of the field. e.g. #profile_field_8_3
( both these ids can be found by inspecting the profile fields via your devtools ; F12 )
user_id : The id of the user to be modified.
value : The new value for the profile field. If it's a list of images you'll use numbers like in my example above. 0 = no warning, 1 = 1 warning, etc.. It depends how your images are ordered.

Lastly you can execute a callback function and check the return data which is in JSON format.
Wolfuryo
Wolfuryo

Gender : Male
Posts : 256
Points : 3597
Reputation : 81
Language : Romanian and English
Browser : Browser : Mozilla Firefox Forum Version : Forum Version : Other

PostWolfuryo Sun 08 May 2016, 12:07

Thanks you. It's working well.
Ange Tuteur
Ange Tuteur
Administrator
Gender : Male
Posts : 4741
Points : 12043
Reputation : 2375
Location : Pennsylvania
Language : EN, JA, FR
Browser : Browser : Brave Forum Version : Forum Version : Forumactif Edge
https://sethclydesdale.github.io/ https://twitter.com/sethc1995

PostAnge Tuteur Sun 08 May 2016, 20:51

Anytime Doff
Sponsored content

PostSponsored content

View previous topic View next topic Back to top

Create an account or log in to leave a reply

You need to be a member in order to leave a reply.

Create an account

Join our community by creating a new account. It's easy!


Create a new account

Log in

Already have an account? No problem, log in here.


Log in

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