[wp-trac] [WordPress Trac] #15291: receiving data with response from ajax call

WordPress Trac wp-trac at lists.automattic.com
Thu Nov 4 18:11:47 UTC 2010


#15291: receiving data with response from ajax call
-----------------------------+----------------------------------------------
 Reporter:  christian_gnoth  |        Owner:         
     Type:  defect (bug)     |       Status:  closed 
 Priority:  normal           |    Milestone:  3.1    
Component:  General          |      Version:  3.0.1  
 Severity:  normal           |   Resolution:  invalid
 Keywords:  ajax,response    |  
-----------------------------+----------------------------------------------
Changes (by azaozz):

  * status:  reopened => closed
  * resolution:  => invalid


Comment:

 I think you're missing some of the AJAX basics here. You make an AJAX call
 that connects to the WordPress back-end, then you need to intercept that
 call (the hook in admin-ajax.php works well for that), then you need to
 run your backend function(s), do whatever you need in php, echo a response
 and `exit()`. That response could be a simple string if you only need -1,
 1, post_ID, etc. or it can be encoded and contain more data.

 There are two popular methods of encoding more complex responses: json and
 xml. Json is native JavaScript and jQuery works with it directly, xml has
 to be parsed to get the actual values. WP_Ajax_Response and wp-ajax-
 response.js are used to encode/decode xml responses.

 In any case there will be no response if your php function doesn't `echo`
 anything or doesn't use WP_Ajax_Response.

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/15291#comment:15>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list