Loading a plugin template via ajax I'm trying to load a plugin template via ajax inside another plugin template like so: 

 $("#modal").load("/mypluginname/myplugintemplatefolder/myplugintemplate.html?queryvar="+var); 


but it keeps looking for myplugintemplate.html on the frontend templates folder instead of in my plugin template folder - I don't understand how to tell it that I'm trying to load a file from my plugintemplate folder

Basically I'm trying to refresh a section of my template by reloading an include
Plugin files are located outside your web root, thats why you can't access them directly. You should create a controller action and render the template from there.

class DefaultController extends Controller{
  protected $allowAnonymous = ['getTemplate'];

  public function actionGetTemplate(){
    $request = Craft::$app-&gt;getRequest();
    $templatevar = $request-&gt;getParam('templatevar');

    use craft\web\View;
    $oldMode = \Craft::$app-&gt;view-&gt;getTemplateMode();
    \Craft::$app-&gt;view-&gt;setTemplateMode(View::TEMPLATE_MODE_CP);
    $html = \Craft::$app-&gt;view-&gt;renderTemplate('plugin-handle/path/to/template');
    \Craft::$app-&gt;view-&gt;setTemplateMode($oldMode);
  }
}


(see https://docs.craftcms.com/v3/extend/updating-plugins.html#rendering-templates)

You can define the route to your controller action in your plugin file

public function init(){
  Event::on(UrlManager::class, UrlManager::EVENT_REGISTER_SITE_URL_RULES, 
  function(RegisterUrlRulesEvent $event) {
      $event-&gt;rules['gettemplate/&lt;templatevar:\w+&gt;''] = 'myPlugin/getTemplate';
  });
}


and call it via
 $("#modal").load("/gettemplate/"+templatevar);