[wp-hackers] AJAX from wp-admin/edit.php

John Gadbois jgadbois at gmail.com
Tue Jul 27 16:05:53 UTC 2010


Sorry to bug everyone.  The href of my anchor was href='javascript:' and for
some reason that was breaking it unless I did an event.preventDefault().

On Tue, Jul 27, 2010 at 11:50 AM, John Gadbois <jgadbois at gmail.com> wrote:

> 1.  I'm capturing via with jQuery.  The post is going out as I can see it
> in Chrome and I also get an empty alert(). Below are my headers...
>
>    1.
>    2. Request URL:
>    http://www.versailles.com/wp-admin/admin-ajax.php
>    3. Request Headers
>       1. Accept:
>       */*
>       2. Cache-Control:
>       max-age=0
>       3. Content-Type:
>       application/x-www-form-urlencoded
>       4. Origin:
>       http://www.versailles.com
>       5. Referer:
>       http://www.versailles.com/wp-admin/edit.php
>       6. User-Agent:
>       Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/533.4
>       (KHTML, like Gecko) Chrome/5.0.375.99 Safari/533.4
>       7. X-Requested-With:
>       XMLHttpRequest
>       4. Form Data
>       1. action:
>       check_copyscape
>       2. id:
>       post-623
>
>
> As you can see there is no status code or request type being sent (no 404,
> 200 OK, or anything).
>
> 2.  I'm posting according to the recommended approach and the same way I've
> done before successfully.
>
> 3. Here's the code...
>
> <?php
> add_action('admin_head', 'copyscape_javascript');
>
> function copyscape_javascript() {
> ?>
> <script type="text/javascript" >
> jQuery(document).ready(function($) {
>    $('.checkCopyscape').live('click', function() {
>       var row = $(this).closest("tr");
>
>       var data = {
>          action: 'check_copyscape',
>          rowId: row.attr('id')
>       };
>
>       jQuery.post(ajaxurl, data, function(response) {
>          alert(response);
>          if(response)
>          {
>             row.data('oldHtml', row.html());
>             row.html(response);
>             row.addClass('inline-edit-row');
>          }
>          else
>          {
>
>          }
>       });
>    });
> });
> </script>
> <?php
> }
>
>  add_action('wp_ajax_check_copyscape', 'copyscape_ajax_check');
>
> function copyscape_ajax_check()
> {
>    echo "IN HERE";
>    die();
> }
> ?>
>
> On another plugin I'm working on that works the headers are different...
>
>
>    1. Request URL:
>    http://www.versailles.com/wp-admin/admin-ajax.php
>    2. Request Method:
>    POST
>    3. Status Code:
>    200 OK
>    4. Request Headers
>       1. Accept:
>       */*
>       2. Content-Type:
>       application/x-www-form-urlencoded
>       3. Origin:
>       http://www.versailles.com
>       4. Referer:
>
>       http://www.versailles.com/wp-admin/admin.php?page=textbroker_completed_orders
>       5. User-Agent:
>       Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/533.4
>       (KHTML, like Gecko) Chrome/5.0.375.99 Safari/533.4
>       6. X-Requested-With:
>       XMLHttpRequest
>       5. Form Data
>       1. action:
>       text_broker_view_order
>       2. order_id:
>       580986
>       6. Response Headers
>       1. Cache-Control:
>       no-cache, must-revalidate
>       2. Connection:
>       Keep-Alive
>       3. Content-Type:
>       text/html; charset=UTF-8
>       4. Date:
>       Tue, 27 Jul 2010 15:46:46 GMT
>       5. Expires:
>       Sat, 26 Jul 1997 05:00:00 GMT
>       6. Keep-Alive:
>       timeout=5, max=100
>       7. Server:
>       Apache/2.2.15 (Unix) mod_ssl/2.2.15 OpenSSL/0.9.8m DAV/2
>       mod_auth_passthrough/2.1 mod_bwlimited/1.4 FrontPage/5.0.2.2635
>       8. Transfer-Encoding:
>        chunked
>       9. X-Powered-By:
>       PHP/5.2.13
>
>
>
> On Tue, Jul 27, 2010 at 11:39 AM, Paul <paul at codehooligans.com> wrote:
>
>> Ok. I'll bite. Smells like a support request but here it goes. I just
>> implemented this on a custom plugin. So feeling I might be qualified to
>> answer. But no promises. Some questions.
>>
>> 1. You added the link. Ok, how are you capturing the click event? Assumed
>> some jQuery or whatever. Have you checked to make sure this is getting
>> properly captured and processed?
>>
>> 2. Also, via your client event processing you are calling the method to
>> post to the server something similar to the examples described
>> http://codex.wordpress.org/AJAX_in_Plugins
>>
>> 2b. You mentioned adding debug to admin-ajax.php. Are you using Firefox +
>> Firebug? You should at least be able to see the post of your message to the
>> server. Anything?
>>
>> 3. How about some code to review?
>>
>> P-
>>
>>
>> On Jul 27, 2010, at 11:24 AM, John Gadbois wrote:
>>
>> > I'm attempting to do an AJAX call from wp-admin/edit.php (I added a link
>> > after Quick Edit, through the post_row_actions filter for a plugin).
>>  For
>> > some reason it's not working.  I've verified in Chrome developer tools
>> that
>> > the request is getting sent to the correct URL, but I'm not getting any
>> > response at all from the server.  I even put a debug line and die() at
>> the
>> > top of admin-ajax.php and it didn't return a response.  I've set up AJAX
>> > successfully on other pages specific to my plugin in the admin section.
>> >
>> > I'm posting using ajaxurl, so it isn't a typo or anything like that.
>> >
>> > Any ideas?
>> > _______________________________________________
>> > wp-hackers mailing list
>> > wp-hackers at lists.automattic.com
>> > http://lists.automattic.com/mailman/listinfo/wp-hackers
>>
>> _______________________________________________
>> wp-hackers mailing list
>> wp-hackers at lists.automattic.com
>> http://lists.automattic.com/mailman/listinfo/wp-hackers
>>
>
>


More information about the wp-hackers mailing list