Topic Closed
a2exfr
242 Posts
26.3K Downloads
2 Themes
10 Plugins

This work before and now can't get  my respond from filter. 

I always get respond with  ([{DO:"replace",SELECTOR:"#gpx_content",CONTENT:"

1- in addon in filter is set like this

[PageRunScript]
script = Admin_My.php
method = Admin_My::PageRunScript

notice: If I change method to non existing no warning appears!

2 - in plugin

    function PageRunScript($cmd) {
    global $page, $addonRelativeCode;

    if ( $cmd == 'test' ) {
      $page->ajaxReplace = array();
        
    $arg_value= "test";
      
    $page->ajaxReplace[] = array('my_respond', 'arg', $arg_value);
      return 'return';
    }

    return $cmd;
  }

3- in js

  $(".test").click(function(){
             
    var href = jPrep(window.location.href) + '&cmd=test';
         
    var jqxhr = $.getJSON(href, ajaxResponse)

    });
 
  $gp.response.my_respond = function(arg) {
                     console.log(arg.CONTENT);
                    
    }

 

Edited: 4 years ago#9268

a2exfr
242 Posts
26.3K Downloads
2 Themes
10 Plugins

And I have one more qwestion

How to avoid:

(XSS Verification Parameter Mismatch)  in my $.ajax  to admin plugin page?

How to make request valid?

 

EDIT:  what value need to pass in $_POST['verified'] or how  add nonce in request. Of cause XSS check can be comment but i dont want to.

Edited: 4 years ago#9269

Josh S.
2K Posts
283K Downloads
16 Themes
18 Plugins

Sounds like the problem might be since this situation uses admin pages. Admin pages don't have the PageRunScript filter.

INI

;Define a script that is only accessible to administrators with appropriate permissions
[Admin_Link:Admin_My]
label    = 'Admin Example'
script = Admin.php
class    = Admin_My

PHP

class Admin_My{

    function __construct(){
        global $page;

        gpPlugin::js('script.js');


        $cmd = common::GetCommand();

        if( $cmd == 'test' ) {
            $page->ajaxReplace = array();

            msg($_REQUEST);

            $arg_value = "test";
            $page->ajaxReplace[] = array('my_respond', 'arg', $arg_value);
            return;
        }

        echo '<p>';
        echo common::Link('Admin_My','Test','cmd=test','class="test"');
        echo '</p>';
    }

}

JS

$(function(){

    $('.test').click(function(evt){

        evt.preventDefault();

        var href            = jPrep(window.location.href) + '&cmd=test';
        $.getJSON(href,ajaxResponse);

    });

    $gp.response.my_respond = function(arg){
        console.log('my respond',arg.CONTENT);
    }

 });

The verified parameter can be added like so:

var href            = jPrep(window.location.href) + '&cmd=test&verified='+encodeURIComponent(post_nonce);

4 years ago#9271

a2exfr
242 Posts
26.3K Downloads
2 Themes
10 Plugins

The verified parameter work perfect! Thank you.

As for the responce

msg($_REQUEST);  is fired but responce is still

([{DO:"replace",SELECTOR:"#gpx_content",CONTENT:"

 

4 years ago#9272

Josh S.
2K Posts
283K Downloads
16 Themes
18 Plugins

Make sure you have this:

global $page;
$page->ajaxReplace = array();

4 years ago#9273

a2exfr
242 Posts
26.3K Downloads
2 Themes
10 Plugins

my bad -  miss global $page;  inside function.

seems time to have a rest )

 but this encodeURIComponent(post_nonce);  really help me     its appears from in 5.1 vers as I see

4 years ago#9274

Topic Closed

 

News

elFinder 2.1.50 in Upcoming Release
12/28/2019

A new release for Typesetter is in the works with a lot of improvements including the ... Read More

Typesetter 5.1
8/12/2017

Typesetter 5.1 is now available for download. 5.1 includes bug fixes, UI/UX improvements, ... Read More

More News

creisi productions

Dienstleistungen von creisi productions, Luzern (Schweiz): * Konzeption, Planung und Erstellung Ihres Internet-Auftritts * Betreuung und Aktualisierung/Pflege Ihrer Website * ...

Find out more about our Provider Spotlight

Log In

  Register