SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Threaded View

  1. #1
    SitePoint Member
    Join Date
    Jun 2014
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Problems inserting AJAX response into page

    Hello,

    I found this post very helpful. I was able to follow it nearly to completion but am having one last issue I hope you can help me with. I have the ajax portion working correctly and my PHP returns an array of informantion using json encoding. My problem is getting that data into the text boxes on my page. If I set the AjaxRequest function like this:

    Code:
    function makeAjaxRequest(opts){
            $.ajax({
              type: "POST",
              data: {opts: opts},
    		  //dataType: "json",
              url: 'wp-admin/admin-ajax.php?action=get_info',
              success: function(res) {
                $("#results").html( res );
              },
    		  error: function (xhr, ajaxOptions, thrownError) {
                alert(xhr.status);
                alert(thrownError);
              }
            });
          }
    the result gets displayed on the page like this:
    {"first_name":["Christine"],"last_name":["Kenney"],"nickname":["ckenney3"],"description":[""],"rich_editing":["true"],"comment_shortcuts":["false"],"admin_color":["fresh"],"use_ssl":["0"],"show_admin_bar_front":["true"]}

    If I uncomment the dataType: "json" line, I no longer get the results displayed. I was sure that the datatype would need to be set to json in order to use the insertResults() function to populate the textboxes. the function that gets called with ajax is:

    Code:
    function get_info(){
    	$data = get_user_meta($_POST['opts']);
    	$response = json_encode($data);
    	echo $response;
    	exit;
    }
    I have tried to use the insertResults() function without setting the datatype to json as well as setting the datatype to json. it makes no difference. Any ideas of where I went wrong here?
    Last edited by Pullo; Jun 17, 2014 at 23:26. Reason: Split into new thread. Made greeting generic


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •