Skip to:
Content
Pages
Categories
Search
Top
Bottom

WPAjax and responseText


  • M
    Member

    @box87

    Here’s the code:

    var commodAjax = new WPAjax( false, 'post-'+postid );
    commodAjax.options.parameters += '&action=rate_post&id=' + postid + '&rate=' + rate;

    // Execute Order 66
    commodAjax.request(commodAjax.url);
    alert(commodAjax.responseText);

    Here’s the response: undefined

    According to FireBug, I am successfully sending postdata and getting a response of “1”. I’d like to take the response and make use of it, but it’s not working.

    I’m writing an extension that allows post rating (user moderation) and this is the final hitch I’m running into. I want to make sure that if the request is not sucessful (ie, it returns 0 or -1) that the browser doesn’t continue executing stuff.

    Sorry, it’s a bit borked, I’ll post more code if necessary.

Viewing 4 replies - 1 through 4 (of 4 total)
  • You misunderstand how xmlhttpresponse works. It’s not like a function call. There is a lot of help using Ajax at http://www.google.com/search?q=xmlhttprequest and http://www.google.com/search?q=ajax. I also suggest you ask for Ajax help on a specialised ajax forum.


    M
    Member

    @box87

    I find it a bit insulting that all I get is Google links. Don’t get me wrong… for most people who don’t search the forums that’s a great solution. I have searched the forums and Google extensively however, and I’m not seeing a whole lot of helpful stuff when it comes to WordPress’s custom wpAjax class. I’ve gone over prototype tutorials, documentation pages, and more and I haven’t found a solution.

    Also, please explain yourself a little further regarding your “function call” comment. Are you referring to commodAjax.request(commodAjax.url);? Because I believe that’s correct. At least that’s how other people have been doing it. If you’re talking about alert(commodAjax.responseText); that was for debug purposes only. I’m trying to get the value. That’s my original request.


    Sam Bauers
    Participant

    @sambauers

    Try:

    alert(commodAjax.transport.responseText);

    I’m not sure if it will work though.

    Would it be too insulting to refer you to the source code of the WPAjax class? There are answers there if you are able to interpret the code.

    Also, if you are not actually returning some output at the page you are requesting, then it might be returning undefined. Again I’m not sure, being that I (like fel64) volunteer my time to answer queries here, I am not necessarily able to fully troubleshoot your issue (especially since you only present half of the equation – i.e. the client side AJAX request).

    You catch more flies with honey. Etc., etc.


    M
    Member

    @box87

    Hmm, I tried that yesterday and it didn’t seem to work. I checked out the WPAjax class and tried commodAjax.transport.responseText, this.responseText, and a couple more variations on that theme.

    Once I get an admin backend for my plugin I’m going to upload it so that everyone can see the source. It’ll probably be a little easier to answer questions then.

    commodAjax.request(commodAjax.url); is requesting the admin-ajax.php file, sending it some postdata, and it’s responding with a 1 (success), 0 (borked data), or -1 (permissions error).

    Thanks.

Viewing 4 replies - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.
Skip to toolbar