Jump to content

hsammak

Members
  • Posts

    5
  • Joined

  • Last visited

Everything posted by hsammak

  1. Hi, I'm trying the simple json return example, all I've done is change the url to the page I'm requesting: <ul id='info'></ul> <script type='text/javascript'> var url = '/wishlist/func_wishpage/'; // this is homepage, so replace '/' with page URL you want to load JSON from $(document).ready(function() { $.getJSON(url, function(data) { $.each(data, function(key, value) { $("#info").append("<li>" + key + ": " + value + "</li>"); }); }); }); </script> The page I'm requesting, with just some dummy info: <?php if($config->ajax) { // this is an ajax request, return basic page information in a JSON string $json = array( 'id' => 3333, 'something' => "else", ); echo json_encode($json); return; } It does not return any values, am I missing something?
  2. Using if($config->ajax) has got it working now! I need to read about input validation, santize etc. Do you know of any good guides/posts to get me started? The code snippet with those variables I used was just an example I took to get the concept working, I will change all that up. Thank you for your help
  3. From reading the forums, I think I might need to take make the php file a template? I have created the template in processwire backendv (func_addpage) and created a page of the same name "func_addpage". What is the best way to refer to the page url? Like this? $.post("<?= $pages->get(1243)->url ?>" <script> $(document).ready(function(){ $("button").click(function(){ $.post("<?= $pages->get(1243)->url ?>", function(data, status){ alert("Data: " + data + "\nStatus: " + status); }); }); }); </script> Doesn't seem to do anything....
  4. I should also state, I'm only getting errors when trying to run processwire API commands on button click. The button click script works if I run a basic php script like: echo "hello world"
  5. Hi, I'm just trying to create a button which when you click it will run a php file that adds a page (without page refresh): This is the jquery/ajax: <script> $(document).ready(function(){ $("button").click(function(){ $.post("/site/templates/func_addpage.php/", function(data, status){ alert("Data: " + data + "\nStatus: " + status); }); }); }); </script> <button id="but_add">Add to wishlist</button> This is the php file I'm trying to run "func_addpage.php" <?php namespace ProcessWire; /* add to a page object with parent path and new pages template name */ $newPage = $pages->add('prod_ratings', '/wishlists', $randTitle, array( 'title' => $sanitizer->text($randTitle), 'api_test_hash' => $randHash ))->setOutputFormatting(true); ?> This code works if I just run it to the page on it's own, without a button click. The issue is when I try to run the php file by using a button click, I just receive an error. I've been reading up on this in the documentation and forum, and I can't seem to find a solution. I've tried making the php file a template, and then trying to call it. I've tried moving the php file into a folder in the root directory, instead of the templates folder. Any guidance would be appreciated. Thanks.
×
×
  • Create New...