Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+1 vote
520 views
in Q2A Core by
Though posting questions, answers and comments works fine when external users are set to WordPress, the Ajax routines will not work. This prevents voting, and the update buttons in Admin Statistics.

All these fail with 'Failed to connect to site' message. Chrome browser reports 'Refused to set unsafe header "Content-length"' and 'Refused to set unsafe header "Connection"'

I've reached the end of my very limited knowledge of Ajax. I can see how the Q2A php and js files are supposed to work, but I just can't bring it all together to find the correct fix.

Any pointers on how to debug this issue further would be appreciated.
related to an answer for: How can I integrate it with wordpress?

1 Answer

+2 votes
by
 
Best answer
The most likely explanation is that something is being output by the file you modified, and this is interfering with the Ajax response.

If that isn't easy to spot, please post a link to your site, and I'll check out exactly what content is coming back in the HTTP response.
by
Thank you for the very fast response.

http://www.shrewdies.net/web-hosting-questions/
by
OK, so in your case, the Ajax response is coming back empty. This is likely to be because there was some kind of PHP error that shut the script down early. Please check your Apache error_log file and see if there's an error there.
by
No, nothing in the error log. Normal log reads:
"POST /web-hosting-questions/qa-include/qa-ajax-vote.php HTTP/1.1" 200 - "http://www.shrewdies.net/web-hosting-questions/"

I've tried stepping through, but the trail stops at jxs_compressed.js

I'm going to have to leave this now until tomorrow, so I will investigate more then.
by
OK, one way to debug it would be to add lots of:

echo __LINE__."\n";

statements inside the file qa-ajax-vote.php, and in addition add an

alert(response);

line inside qa-votes.js, just after:

function(response) {

That way you'll get a message in the browser showing you which lines of qa-ajax-vote.php were successfully executed, and where it failed. If this is to do with the external user code I suspect it will be related to qa_get_logged_in_user(...)

Actually, at a guess, it will be because the relative path you use in your require(...) in qa-external-users.php is not working because the Ajax voting PHP file is in a different directory to index.php. Instead you can try an absolute path, or one based on the QA_BASE_DIR constant, which will be defined the same for all requests.
by
"Instead you can try an absolute path"

You are an absolute star!

Voting and database cleanup operations now work fine. I'll amend my previous answer to suit.
...