{"id":10565978,"date":"2018-08-07T05:58:23","date_gmt":"2018-08-07T05:58:23","guid":{"rendered":"https:\/\/wordpress.org\/support\/topic\/call-code-snippet-from-javascript\/"},"modified":"2018-08-07T05:58:23","modified_gmt":"2018-08-07T05:58:23","slug":"call-code-snippet-from-javascript","status":"publish","type":"topic","link":"https:\/\/wordpress.org\/support\/topic\/call-code-snippet-from-javascript\/","title":{"rendered":"Call code snippet from javascript"},"content":{"rendered":"<p>I would like to have JavaScript call a PHP function defined in a snippet but what would be the url for ajax?<\/p>\n<p>$(&#8216;.button&#8217;).click(function() {<br \/>\n$.ajax({<br \/>\n  type: &#8220;POST&#8221;,<br \/>\n  url: &#8220;some.php&#8221;,<br \/>\n  data: { name: &#8220;John&#8221; }<br \/>\n}).done(function( msg ) {<br \/>\n  alert( &#8220;Data Saved: &#8221; + msg );<br \/>\n});<br \/>\n});<\/p>\n<p>&lt;?php<br \/>\nfunction abc($name){<br \/>\n\/\/your code here<br \/>\n}<br \/>\n?&gt;<\/p>\n","protected":false},"template":"","class_list":["post-10565978","topic","type-topic","status-publish","hentry"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/10565978","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic"}],"about":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":0,"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/10565978\/revisions"}],"wp:attachment":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/media?parent=10565978"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}