0

Here's the code:

jQuery.post('/assets/api/addToPicks.php', {imagePath: theImagePath, clientPath: theClientPath}, function() {
    jQuery.get('/site/templates/snippetServer.php', function(data) {
        jQuery('#picks').html(data);
    });
});

The first call to /assets/api/addToPicks.php works fine (I've tried it all by itself and get no error).

But the second call to /site/templates/snippetServer.php generates a consistent error (even when called by itself, separate from the jQuery.post()):

http://www.brp.dev/site/templates/snippetServer.php    301 Moved Permanently

Both files do exist at those paths.

I am stumped.

Bob

Bob Rockefeller
  • 4,492
  • 2
  • 28
  • 35

1 Answers1

1

You are doing a similar mistake I've replied a few mins ago. Basically you are calling a jQuery.get() after a jQuery.get() which makes two ajax calls.

As per your code you should be able to serve one request from server side addToPicks.php OR snippetServer.php and make a single call deciding whether it should be by GET or POST.

For your case I think jQuery.load() method should be the best solution:

jQuery('#picks').load('/assets/api/your_one_file_serving_the_html.php', {imagePath: theImagePath, clientPath: theClientPath});
Community
  • 1
  • 1
Adit Saxena
  • 1,617
  • 15
  • 25
  • Hmmm. But even when jQuery.get('/site/templates/snippetServer.php', function(data) { jQuery('#picks').html(data); }); is called by itself, I still get the 301. And if I combine the functions, that's the one I need to combine them in. – Bob Rockefeller Jun 09 '13 at 14:14
  • Is your page at snippetServer.php able to serve http GET request? You should be able to get in the browser /site/templates/snippetServer.php?imagePath=...&var2=val&... – Adit Saxena Jun 09 '13 at 14:17
  • I'm using the Kirby CMS framework (it's PHP). The snippetServer.php file is just a very short PHP snippet. – Bob Rockefeller Jun 09 '13 at 14:24
  • I think you should isolate your problem: please check from your browser if its working with the simple GET request as I suggested above, otherwise is a jQuery problem which I think is unlikely in your case. Please look also where it wants you to redirect: mostly you will see an error page (a misspelled word, someother error)! – Adit Saxena Jun 09 '13 at 14:33
  • Is the redirect happening because it can't find the file, thinks the file moved, or because there's something wrong in the file? I haven't been able to affect the results with anything I've put into the snippetServer.php file. The call just never seems to get to snippetServer.php. The way Kirby CMS works, I can't call that file direct from the server, Kirby wants to grab the url and route it. – Bob Rockefeller Jun 09 '13 at 14:43
  • Whats the output of: http://localhost/assets/api/snippetServer.php?imagePath=&clientPath= and where it wants you to redirect? – Adit Saxena Jun 09 '13 at 22:30
  • I finally figured it out. It wasn't an AJAX or jQuery problem at all. It had to do with the framework I'm using (Kirby) - I shouldn't have been calling the template directly. Thanks for the comments, everyone. – Bob Rockefeller Jun 10 '13 at 01:45