0

I'm having a bit of an issue with my jQuery code. It runs a an ajax request through jQuery.POST to run a .php file. After that the results are displayed in a div. The problem I am having is that the results are not being displayed, but the .php file is definitely being executed as the values are being updated when I refresh the page.

In the console I get the following error.

POST http://domain.com/path/to/my/file/myfile.php 404 (Not Found) jquery.js?ver=1.8.3:2
send jquery.js?ver=1.8.3:2
v.extend.ajax jquery.js?ver=1.8.3:2
v.(anonymous function) jquery.js?ver=1.8.3:2
(anonymous function) domain.com/url/function/here/:2723
v.event.dispatch jquery.js?ver=1.8.3:2
o.handle.u jquery.js?ver=1.8.3:2

Here is my jQuery code

                    jQuery('.wantedStatus').on('click', function(event)
                    {
                            var anime_id = <?php echo $anime_id; ?>;
                            var anime_list_entry_id = <?php echo $anime_list_entry_id; ?>;
                            var wantedStatus = jQuery(this).text();

                                jQuery.post("/path/to/my/file/myfile.php", {firstParam : anime_id, secondParam : anime_list_entry_id, thirdParam : wantedStatus}, function(data) {
                                    //this is your response data from serv
                                console.log(data);
                                jQuery('#anime_list_update').html(data);

                            });
                                return false;
                    });

and here is the myfile.php code...

<?php

require('/home2/phanime/public_html/wp-blog-header.php');

$anime_id = $_POST['firstParam'];
$anime_list_entry_id = $_POST['secondParam'];
$wantedStatus = $_POST['thirdParam'];

$total_episodes = get_post_meta($anime_id, 'anime_total_episodes', true);
$episodes_seen = get_post_meta($anime_list_entry_id, 'episodes_seen_list_entry', true);
$score = get_post_meta($anime_list_entry_id, 'score_anime_list_entry', true);

update_post_meta($anime_list_entry_id, 'status_list_entry', $wantedStatus);

echo $status = get_post_meta($anime_list_entry_id, 'status_list_entry', true);

?>

<?php get_entry_anime_list_text($status, $score, $episodes_seen); ?>

The ending function get_entry_anime_list_text(params) is what is suppose to be outputted. However, nothing is being outputted and on top of that I am getting that error in the console.

I've tried commenting out get_entry_anime_list_text() function but the error still exists.

Does anyone have an idea why this error is popping up?

Maaz
  • 4,193
  • 6
  • 32
  • 50
  • Is the file actually located at `/path/to/my/file`, or is that just an example? –  Aug 15 '13 at 16:57
  • Can you open `http://domain.com/path/to/my/file/myfile.php` in the browser? And if it shows up, does it return a `200 OK` response or a `404 Not Found` status? (Check network panel of debugger tools). – Salman A Aug 15 '13 at 16:59
  • Yeah, check the path to your file. That's the likely culprit. – JRizz Aug 15 '13 at 17:00
  • The weirdest part is, that the file is actually there and I can open it in my browser with that path. I know for a fact that the jQuery is running it properly as well since I've stated that the values are actually being updated. It's just that the `console.log(data)` is returning the NOT Found error. Which makes me think that the `data` that's being returned from the .php file is not right? – Maaz Aug 15 '13 at 17:02
  • But that doesn't seem to be the case either. I've commented out the `get_entry_anime_list_text(params)` function and just used `echo 'test';` right at the end, but that throws out the same error. – Maaz Aug 15 '13 at 17:06
  • @Faeron: if it is wordpress it is not unusual for a page to execute normally but send a 404 not found header. See my earlier comment (adding wordpress tag). – Salman A Aug 15 '13 at 17:16
  • @SalmanA this is Wordpress, and in the network tab it does show 404 Not Found (Text). And in the Type it shows text/html. By the way, this method was previously working, I'm thinking this could be wordpress related? – Maaz Aug 15 '13 at 17:52
  • Check [this](http://stackoverflow.com/a/13614297/1287812) and [this](http://stackoverflow.com/a/17530849/1287812) – brasofilo Aug 16 '13 at 08:54

0 Answers0