Results 1 to 8 of 8

Thread: jQuery, Ajax, WP, posting 4000B long text: 404 not found (2000B=OK)

  1. #1
    Join Date
    Nov 2011

    Unhappy jQuery, Ajax, WP, posting 4000B long text: 404 not found (2000B=OK)

    Hello guys

    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,

  2. #2
    Join Date
    Dec 2005
    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 02:42 PM.
    I've switched careers...
    I'm NO LONGER a scientist,
    but now a web developer...

  3. #3
    Join Date
    Nov 2011


    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?

        './configure' '--disable-mbregex' '--enable-bcmath' '--enable-calendar' '--enable-exif' '--enable-force-cgi-redirect' '--enable-ftp' '--enable-gd-native-ttf' '--enable-libxml' '--enable-magic-quotes' '--enable-mbstring' '--enable-pdo=shared' '--enable-sockets' '--enable-zip' '--prefix=/usr' '--with-curl=/opt/curlssl/' '--with-freetype-dir=/usr' '--with-gd' '--with-gettext' '--with-imap=/opt/php_with_imap_client/' '--with-imap-ssl=/usr' '--with-jpeg-dir=/usr' '--with-kerberos' '--with-libdir=lib64' '--with-libxml-dir=/opt/xml2/' '--with-mcrypt=/opt/libmcrypt/' '--with-mhash=/opt/mhash/' '--with-mysql=/usr' '--with-mysql-sock=/var/lib/mysql/mysql.sock' '--with-mysqli=/usr/bin/mysql_config' '--with-openssl=/usr' '--with-openssl-dir=/usr' '--with-pdo-mysql=shared' '--with-pdo-sqlite=shared' '--with-pic' '--with-png-dir=/usr' '--with-sqlite=shared' '--with-ttf' '--with-xpm-dir=/usr' '--with-zlib' '--with-zlib-dir=/usr' '--without-iconv'
        Apache/2.0.63 (Unix) mod_ssl/2.0.63 OpenSSL/0.9.8e-fips-rhel5 mod_auth_passthrough/2.1 mod_bwlimited/1.4 FrontPage/
    Here's the actual receiver, the php code, nothing fancy:
        //header("HTTP/1.1 200 OK");	//this line is required to avoid 404 error
        if (isset($_POST['html']))
        	$s = $_POST['html'];
        else {
        	$s = '';
        if ( !wp_verify_nonce( $_POST['nonce'], 'kwd-nonce' ) ) {
        	echo 0;
        global $wpdb, $kwd;
        switch (@$_POST['action']) {
        	case 'update-settings':
        	default: //'get_kwd_tables':
        /* ===================================== */
        function ajax_update_settings() {
        	global $wpdb, $kwd;
        	if (isset($_POST['exclusion_list']))
        		if (get_magic_quotes_gpc())
        			$newOptions['exclusion_list'] = stripslashes($_POST['exclusion_list']);
        			$newOptions['exclusion_list'] = $_POST['exclusion_list'];
        	if (isset($_POST['exclude_length_min']))
        		$newOptions['exclude_length_min'] = $_POST['exclude_length_min'];
        	$options = $kwd->get_options($newOptions);	//save Ajax posted options from Settings tab
        	echo 1;
        /* =================================== */
        function ajax_get_kwd_tables() {
        	global $wpdb, $kwd; // this is how you get access to the database
        	require_once ('include/htmltools.php');
        	$options = $kwd->get_options();
        	$ht = new htmlTools($_POST['html']);
        	$ht->set('exclusionList', $options['exclusion_list']);
        	$ht->set('excludeLengthMin', $options['exclude_length_min']);
        	$out['tab11'] = $ht->display();
        	header("Content-Type: application/json; charset=utf-8");
        	$x = json_encode($out); //$json->encode($out);
        	echo $x;

  4. #4
    Join Date
    Dec 2005
    What about the code for the XHR?
    I've switched careers...
    I'm NO LONGER a scientist,
    but now a web developer...

  5. #5
    Join Date
    Nov 2011
    What is the XHR code?
    This is the Javascript used to call the ajax page (I also tried with "xhr.setRequestHeader("Content-length", 0) and got the "Refused to set unsafe header "Content-length" in the console, and same 404 error):
    var data1 = {
        action: 'get-tables',
        html: $('#content').val(),
        nonce: kwd_settings.nonce
        url: kwd_settings.ajax_url,
        type: 'POST',
        data: data1,
        scriptCharset: 'utf-8',
        timeout: 10000, /*10 seconds*/
        beforeSend: function( xhr ) {
            xhr.setRequestHeader("Content-length", $('#content').val().length+500);
        error: function (request, ajaxOptions, thrownError) {
        success: function( response ) {
            var r= response;

  6. #6
    Join Date
    Dec 2005
    Why are you setting the content length header before sending? If this is jQuery, and it looks like it is, it's not required, jQuery does all this for you.

    Does it make a difference if you get rid of this beforeSend method?
    I've switched careers...
    I'm NO LONGER a scientist,
    but now a web developer...

  7. #7
    Join Date
    Nov 2011
    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...

  8. #8
    Join Date
    Nov 2011
    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...

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center



X vBulletin 4.2.2 Debug Information

  • Page Generation 0.10679 seconds
  • Memory Usage 2,923KB
  • Queries Executed 15 (?)
More Information
Template Usage (33):
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_global_above_footer
  • (1)ad_global_below_navbar
  • (1)ad_global_header1
  • (1)ad_global_header2
  • (1)ad_navbar_below
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)ad_thread_first_post_content
  • (1)ad_thread_last_post_content
  • (3)bbcode_code
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)headinclude_bottom
  • (8)memberaction_dropdown
  • (1)navbar
  • (4)navbar_link
  • (1)navbar_moderation
  • (1)navbar_noticebit
  • (1)navbar_tabs
  • (2)option
  • (8)postbit
  • (8)postbit_onlinestatus
  • (8)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available (6):
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files (26):
  • ./showthread.php
  • ./global.php
  • ./includes/class_bootstrap.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/functions_navigation.php
  • ./includes/class_friendly_url.php
  • ./includes/class_hook.php
  • ./includes/class_bootstrap_framework.php
  • ./vb/vb.php
  • ./vb/phrase.php
  • ./includes/functions_facebook.php
  • ./includes/functions_calendar.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_notice.php
  • ./packages/vbattach/attach.php
  • ./vb/types.php
  • ./vb/cache.php
  • ./vb/cache/db.php
  • ./vb/cache/observer/db.php
  • ./vb/cache/observer.php 

Hooks Called (70):
  • init_startup
  • friendlyurl_resolve_class
  • init_startup_session_setup_start
  • database_pre_fetch_array
  • database_post_fetch_array
  • init_startup_session_setup_complete
  • global_bootstrap_init_start
  • global_bootstrap_init_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • load_show_variables
  • load_forum_show_variables
  • global_state_check
  • global_bootstrap_complete
  • global_start
  • style_fetch
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • strip_bbcode
  • friendlyurl_clean_fragment
  • friendlyurl_geturl
  • forumjump
  • cache_templates
  • cache_templates_process
  • template_register_var
  • template_render_output
  • fetch_template_start
  • fetch_template_complete
  • parse_templates
  • fetch_musername
  • notices_check_start
  • notices_noticebit
  • process_templates_complete
  • friendlyurl_redirect_canonical
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • memberaction_dropdown
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • build_navigation_data
  • build_navigation_array
  • check_navigation_permission
  • process_navigation_links_start
  • process_navigation_links_complete
  • set_navigation_menu_element
  • build_navigation_menudata
  • build_navigation_listdata
  • build_navigation_list
  • set_navigation_tab_main
  • set_navigation_tab_fallback
  • navigation_tab_complete
  • fb_like_button
  • showthread_complete
  • page_templates