0

First of all, please don't mark the question as duplicate as I didn't ask how to send arguments with ajax request.

I want to receive some extra arguments on ajax success. My callback function will return some html data. But I want to get some other arguments with that data.

maybe something like:

        success: function( data, arg_1, arg_2 ) {
            if( arg_1 ) {
                $('selector').append( data );
            } else if( arg_2  ) {
                $('other_selector').append( data );
            }
        }

But I don't know how to pass arguments like this. Any idea?

My current callback function makes a query with custom post and uses get_template_part() function to load them.

3

Have you tried returning an array instead?

wp_send_json($an_array_of_your_vals);

And then parse the array in the success function?

success: function( data ) {
   var obj = jQuery.parseJSON(data);

   if( obj.arg_1 ) {
            $('selector').append( obj.content );
   } else if( obj.arg_2  ) {
            $('other_selector').append( obj.content );
   }
}
  • Thx toscho for the edit. – shanebp Jun 21 '15 at 20:54
  • That won't not work for me. In my question, I mentioned that, my callback function uses get_template_part() function. It uses to echo out my result automatically So, I cannot pass them into wp_send_json() function. – Sohan Zaman Jun 22 '15 at 3:44
  • @SohanZaman You can put the output per output buffering into a string. – fuxia Jun 22 '15 at 7:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.