SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Threaded View

  1. #1
    SitePoint Member
    Join Date
    Jun 2014
    0 Post(s)
    0 Thread(s)

    Problems inserting AJAX response into page


    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:

    function makeAjaxRequest(opts){
              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) {
    the result gets displayed on the page like this:

    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:

    function get_info(){
    	$data = get_user_meta($_POST['opts']);
    	$response = json_encode($data);
    	echo $response;
    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


Posting Permissions

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