jQuery, Ajax, WP, posting 4000B long text: 404 not found (2000B=OK)
It's my first post/thread here, I haven't been active in forums for some time cause frankly I didn't need it, but this one just got me.
I tried everything in my knowledge -and I mean everything, I'm a fanatic trial-and-error tester.
jQuery, posts some data through Ajax collected primarily from a $('#textarea') to a php file on server.
If the data is >X Bytes, I get 404 Not Found and the 404 Html page in Ajax error handler.
Otherwise, everything runs smoothly and I get my results.
I must specify that I post to a php file that loads Wordpress's wp-blog-header.php before doing calculations, as the code is intended to be part of a WPplugin.
I tried to return header("HTTP/1.1 200 OK") as some suggested, considering WP was altering the header for not finding the file as part of the system, and it solved the issue locally for some cases, but not remotly.
I tried to set the Content-Length in ajax call.
I switched between the WP type of handling Ajax calls, and having my own .php file, in the folder of my plugin.
Nothing worked, but trimming content.
What could this be? post_data_size is 8M on server.
Could this be maybe related to SSL as I've seen in some cases?
I'm lost here.
Thanks for your help,
I don't think it has anything to do with the length of the text, 4000b is less than 4Kb - if you can't post 4Kb through an ajax call then there's something wrong with the whole system.
I've got my money on the fact that you're including the blog-header and it's spitting out the 404 error.
Hard to say without seeing the PHP and it'd probably still be hard to say without seeing the code and a testing environment.
All I can advise though, is that if you need to include the blog header in a PHP file, then you're better off doing AJAX the way WordPress intended - by using the wp_ajax() function and setting the URL of your request to wp-admin/admin-ajax.php
It is weird, however, why it is that the different lengths trigger different errors.
Last edited by aj_nsc; 11-15-2011 at 01:42 PM.
I've switched careers...
I'm NO LONGER a scientist,
but now a web developer...
I assure you: in my ajax file I tried with wp-config, now I left it with wp-load cause I thought it's somewhere in the middle, the way I read was that wp-blog-header.php calls wp-load, which calls in the end wp-config.
But either way, it returns with ajax error 404 AND instead of results, brings back the 404 page (if the results would have been calculated anyway, I would have forced a header(200) and that's it, but they arent't, it's the 404 page).
I agre with the admin-ajax.php situation, however if I call my own ajax file I could disable mod_security at the level of my plugin with an .htaccess file in the plugin folder, otherwise I don't have access to the wp-admin folder and so I couldn't help users easily in case of another infamous kind of error: Mrs. 403 .
Your last line is what surprises me also: how the heck can it work with 2000B, but not 3000B... BYTES... no mega, no kilo, just bytes (.
What would you need from the testing environment? Is this enough?
What is the XHR code?
No, I added the beforeSend because I was desperate, and because I saw that the big influencer was the length of content. So I thought in my innocent mind that maybe, if I would tell it the size of content, something could change.
Yet, nothing changes... I will try to close this blog, and do more tests, although this is already wasting a lot of nervous energy on my part I'm out of solutions...
Same for scriptCharset: 'utf-8' and timeout: 10000, /*10 seconds*/
I added these in "desperation mode", otherwise it works very well without them.
What this plugin does is grab the code from the wordpress content textarea, and send it to a php script to do some analysis on it. Nothing incredible. Yet...