<p>The problem seems related to my structure. Yii expects certain controller name, and since I only used a default naming convention in a single controller, Yii keeps calling this controller only.</p>
<p>The problem is that I have no idea how to structure my plugin correctly. <a href="https://craftcms.com/docs/2.x/plugins/controllers.html#posting-to-controller-actions-with-javascript" rel="nofollow noreferrer">https://craftcms.com/docs/2.x/plugins/controllers.html#posting-to-controller-actions-with-javascript</a> doesn't work for me and 3.x documentation doesn't mention it at all.</p>

CC BY-SA 4.0
2020-08-12T13:15:46.750Z
I would recommend using https://pluginfactory.io/ to create your initial plugin framework, which will give you a good 'best practice' outline of how a Craft plugin should be structured. It's also worth looking at the source code of a few Craft plugins to see how their authors have structured their code.
Martin Spain
CC BY-SA 4.0
2020-08-12T08:47:21.713Z
2020-08-12T08:47:21.713Z
Jan Kokes
<p>Craft 3.x controller endpoints are kebab-case rather than camelCase as with Craft 2.x, and you can post to them via JS very easily using the URL format below:</p>
<pre><code>https://yoursite.com/index.php?p=actions/&lt;plugin-handle&gt;/&lt;controller-name&gt;/&lt;controller-action&gt;
</code></pre>
<p>To take the example from the old Craft 2 docs you linked to above, you can make an Ajax request to the default endpoint of a controller like this:</p>
<pre><code>https://yoursite.com/index.php?p=actions/cocktail-recipes/ingredients
</code></pre>
<p>Or a specific (i.e. non-default) controller action like this:</p>
<pre><code>https://yoursite.com/index.php?p=actions/cocktail-recipes/ingredients/save-ingredient
</code></pre>

CC BY-SA 4.0
2020-08-11T15:50:29.243Z
2020-08-12T13:22:11.640Z
2020-08-12T13:22:11.640Z
Martin Spain
<p>I would like to make multiple Ajax calls from my index.html.</p>
<p>One call comes from $(document).ready() function.
Second one is invoked from .on(&quot;click&quot;) event outside the $(document).ready() loop.</p>
<p>Unfortunately, the second call seemingly takes success callback from the first call. I tested this by calling a.php in first call and b.php in second call. Both calls end up in a.php, and both have identical parameters.
Is there a way to make this work in Craft?</p>

CC BY-SA 4.0
2020-08-11T15:50:43.920Z
From your description, this sounds more like a JavaScript issue than a Craft CMS issue. Could you post a code snippet to better describe what you're trying to achieve?
Martin Spain
CC BY-SA 4.0
2020-08-11T22:15:39.323Z
I’m voting to close this question because it's not related to Craft.
Ian
<ajax><jquery>
Multiple jQuery $.ajax() calls from one template
# Multiple jQuery $.ajax() calls from one template

(Asked by: username_0 on 2020-08-11)

I would like to make multiple Ajax calls from my index.html.

One call comes from $(document).ready() function.
Second one is invoked from .on("click") event outside the $(document).ready() loop.

Unfortunately, the second call seemingly takes success callback from the first call. I tested this by calling a.php in first call and b.php in second call. Both calls end up in a.php, and both have identical parameters.
Is there a way to make this work in Craft?

**Tags:** ajax, jquery

> **Comments:**
> **username_1**: From your description, this sounds more like a JavaScript issue than a Craft CMS issue. Could you post a code snippet to better describe what you're trying to achieve?  
> **username_2**: I’m voting to close this question because it's not related to Craft.  

---

## 2 answers

### Answer by username_0 on 2020-08-12. Score: 1

The problem seems related to my structure. Yii expects certain controller name, and since I only used a default naming convention in a single controller, Yii keeps calling this controller only.

The problem is that I have no idea how to structure my plugin correctly. <https://craftcms.com/docs/2.x/plugins/controllers.html#posting-to-controller-actions-with-javascript> doesn't work for me and 3.x documentation doesn't mention it at all.

> **Comments:**
> **username_1**: I would recommend using https://pluginfactory.io/ to create your initial plugin framework, which will give you a good 'best practice' outline of how a Craft plugin should be structured. It's also worth looking at the source code of a few Craft plugins to see how their authors have structured their code.  

---

### Answer by username_1 on 2020-08-11. Score: 1

Craft 3.x controller endpoints are kebab-case rather than camelCase as with Craft 2.x, and you can post to them via JS very easily using the URL format below:
https://yoursite.com/index.php?p=actions///

To take the example from the old Craft 2 docs you linked to above, you can make an Ajax request to the default endpoint of a controller like this:
https://yoursite.com/index.php?p=actions/cocktail-recipes/ingredients

Or a specific (i.e. non-default) controller action like this:
https://yoursite.com/index.php?p=actions/cocktail-recipes/ingredients/save-ingredient


---

