Solved

AJAX (json) object returned ok on development server but not production server

Posted on 2008-10-02
5
302 Views
Last Modified: 2012-05-05
Ok, this one has me well and truely stumped.

I have the following function that uses jquery to make ajax (json) requests:

function get_content_row(row_id) {
      var session_var = "";
      //alert(row_id);
      var rethtml = $.ajax({
            url: 'admin_json_functions.php',data: 'action=get_content_row&row_id=' + row_id,dataType: 'json',type: 'post',async: false,
            success: function (j) {
                  session_var = j;
      }});      
      return session_var;
}

When this function is called from within Javascript as follows:

var content_row = get_content_row(row_id);
            
alert(content_row['core']['title']);

It works ok on my development server, but on my production server i get the following error:

Error: content_row.core is undefined

The JSON code that is called returns a json_encoded PHP array that is generated from a class and the code is as follows:

if ($_REQUEST['action'] == 'get_content_row' && isset($_SERVER['HTTP_X_REQUESTED_WITH'])) {echo json_encode(get_content_row($_REQUEST['row_id']));exit;}
      

      function get_content_row($row_id) {

            $resp = array();

            $row = new content;
            
            $row->load_content($row_id);

            $resp['core'] = $row->core;
            $resp['category'] = $row->category;
            $resp['author'] = $row->author;
            $resp['media'] = $row->media;
            $resp['taglines'] = $row->taglines;
            $resp['keywords'] = $row->keywords;
            
            
            //return arrayToJS($resp, 'content_row');
            return $resp;
                  
      }            

As I have mentioned, in my dev enviroment (apache 2.2, mysql 5+, php 5+) this all works ok, but in my production server it throughs this error. I understand this may stem back to problems with how the variable may be passed between php and javascript (using ajax as the carrier) and have investigated the following options:

* eval() clientside funciton
* Use of Hash structures and passing through that way.

However this is sort of not my point, what i was hoping to get to the bottom of, is why it may be workign on my dev server, and not production, as if this can be modified to work many, many potential changes to code may be avoided.

Thanks in advance, Jake.
0
Comment
Question by:jacbmw
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
5 Comments
 
LVL 1

Expert Comment

by:santoshrajan
ID: 22631226
Your production server may not be setting the header to application/x-json. set it in your php and try.
0
 

Author Comment

by:jacbmw
ID: 22631992
Do you mean in php.ini, or within the file that returns the json encoded data?
0
 

Accepted Solution

by:
jacbmw earned 0 total points
ID: 22646997
fixed guys, was using version 5.1 of php on prod server, json_encode wasnt a valid function on this version. Installed fix to server and working!
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 35762985
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Local HTML file to display local Access MDB data in browser 4 60
Fix Form size HTML 16 30
JQuery conflicts/syntax issue 4 23
Compute age Html 2 24
OverviewThis article demonstrates a simple search form using AJAX. The purpose of the article is to demonstrate how to use the same code to render a page and javascript (JQuery) and AJAX to make subsequent calls to refine the results. The princip…
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

735 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question