Plugin Directory

Changeset 2309863


Ignore:
Timestamp:
05/22/2020 12:26:27 AM (6 years ago)
Author:
danillonunes
Message:

Pass API call as an parameter in WordPress AJAX call

Location:
makemydonation-imo/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • makemydonation-imo/trunk/js/mmdimo.edit-form.js

    r2126495 r2309863  
    6363  if ($charities.length) {
    6464    $orghunterCSC.orghunterCSC({
    65       apiURL: ajaxurl,
    66       apiData: {
    67         action: 'mmdimo_orghunter_csc_ajax',
    68       },
     65      apiURL: ajaxurl + '?action=mmdimo_orghunter_csc_ajax&mmdimo_api_call=',
    6966      searchAlias: true,
    7067      stateChosen: false,
  • makemydonation-imo/trunk/mmdimo.php

    r2150443 r2309863  
    472472function mmdimo_orghunter_csc_ajax() {
    473473  require_once( MMDIMO_PLUGIN_DIR . '/api.php' );
    474   $path = substr($_SERVER['PHP_SELF'], strlen($_SERVER['SCRIPT_NAME']) + 1);
    475   $spath = explode('/', $path);
     474  $spath = explode('mmdimo_api_call=/', $_SERVER['REQUEST_URI']);
     475  $path = $spath[1];
    476476  $response = array();
    477477
    478   switch ($spath[0]) {
    479     case 'cities':
    480       if (strlen($spath[1]) == 2) {
    481         $response = mmdimo_api_request( 'get', 'orghunter/data/' . $path );
     478  if (substr($path, 0, 6) == 'cities' && strlen($path) == 9) {
     479    $response = mmdimo_api_request( 'get', 'orghunter/data/' . $path );
     480  }
     481  else if (substr($path, 0, 13) == 'charitysearch' || substr($path, 0, 18) == 'charitysearchalias') {
     482    $accepted_parameters = array('eligible', 'state', 'city', 'searchTerm');
     483    foreach ($accepted_parameters as $accepted_parameter) {
     484      if (isset($_GET[$accepted_parameter])) {
     485        $parameters[$accepted_parameter] = $_GET[$accepted_parameter];
    482486      }
    483       break;
    484     case 'charitysearch':
    485     case 'charitysearchalias':
    486       $accepted_parameters = array('eligible', 'state', 'city', 'searchTerm');
    487       foreach ($accepted_parameters as $accepted_parameter) {
    488         if (isset($_GET[$accepted_parameter])) {
    489           $parameters[$accepted_parameter] = $_GET[$accepted_parameter];
    490         }
    491       }
    492       $query = http_build_query($parameters);
    493       $response = mmdimo_api_request( 'get', 'orghunter/data/' . $path . '?' . $query );
    494       break;
     487    }
     488    $query = http_build_query($parameters);
     489    $response = mmdimo_api_request( 'get', 'orghunter/data/' . $path . '?' . $query );
    495490  }
    496491
Note: See TracChangeset for help on using the changeset viewer.