I have a custom jquery plugin I am working on to import forms to elements on a page. The plugin is saved on a file called jquery-library.js and this is imported into my page along with another jquery library jquery.min.js. I can get my plugin to work if I hard code the variable it ajax's to but not if I use this or $(this).
Here is my php page code:
<head>
<meta charset="utf-8">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="scripts/jquery-library.js"></script>
<link href='https://fonts.googleapis.com/css?family=PT+Sans+Narrow:400,700' rel='stylesheet' type='text/css'>
<link type="text/css" href="css/main.css" rel="stylesheet"/>
<script>
$(document).on('click', '#add', function(){
$("div#form-import-container").loadForm("add", "websites");
});
</script>
<title>Senneca Portal | Adminstration Panel</title>
</head>
<body>
<?php require_once("include/header.php"); ?>
<section id="content">
<section id="left-side-bar">
<img id="side-profile-pic" src=""/>
<div id="page-sub-nav-container">
<p class="sub-nav-title"><?php echo $pageDisplay; ?></p>
<nav id="side-nav">
<ul>
<li><a <?php if($page == "overview"){ echo "class='active'";}; ?> href="administration.php">Overview</a></li>
<li><a <?php if($page == "websites"){ echo "class='active'";}; ?> href="administration.php?page=websites">Websites</a></li>
<li><a <?php if($page == "products"){ echo "class='active'";}; ?> href="administration.php?page=products">Products</a></li>
<li><a <?php if($page == "libraries"){ echo "class='active'";}; ?> href="administration.php?page=libraries">Libraries</a></li>
<li><a <?php if($page == "colors"){ echo "class='active'";}; ?> href="administration.php?page=colors">Colors</a></li>
<li><a <?php if($page == "testimonials"){ echo "class='active'";}; ?> href="administration.php?page=testimonials">Testimonials</a></li>
<li><a <?php if($page == "users"){ echo "class='active'";}; ?> href="administration.php?page=users">Users</a></li>
</ul>
</nav>
</div>
</section>
<section id="data">
<button id="add">Add New</button>
<h2><?php echo $pageDisplay." - ".$page; ?></h2>
<!-- Area for form import -->
<div id="form-import-container"></div>
loadForm is my custom plugin I have been making and here is the code for that.
(function($){
$.fn.loadForm = function(action, formName){
$.ajax({url: "include/forms/"+action+"-"+formName+".php", success: function(result){
$("div#form-import-container").html(result);
}});
};
}(jQuery));
This works fine but I want the ajax to import to any element I call the function on.
so this doesnt work and I need it too
(function($){
$.fn.loadForm = function(action, formName){
$.ajax({url: "include/forms/"+action+"-"+formName+".php", success: function(result){
$(this).html(result);
}});
};
}(jQuery));
Why will this not import anything to the element I have the function called on? nothing happens I get no errors and nothing telling me that its error'd out if I add the error function to the ajax call. I dont see what I am doing wrong the this call it should add the content to the element that the function was called on.