SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Jan 2007
    Posts
    26
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    JSON & PHP .. Unexpected error!

    Hi..

    am trying to use json for live update, on local host works fine, but after uploading to the host am getting errors:
    Code:
    Resource interpreted as Script but transferred with MIME type text/html.
    Uncaught SyntaxError: Unexpected token
    in my php file am using json_encode, the local php version is 5.2.9, and json version 1.2.1.

    on the host php verion 5.2.13, json 1.2.1.

    what can the problem !?

    Code:
    $(document).ready(function(){
    function GetData() {
        $.getJSON("http://site.com/get.php?callback=test", null, function(data) {
    
            if (data != null) {
    			$('.test').text(data.latest_price); 
            }
        });
    }
    setInterval(function(){ GetData()  },5000); 
    
    
    });


    Thanks in advanced for any help !

  2. #2
    John 8:24 JREAM's Avatar
    Join Date
    Sep 2007
    Location
    Florida
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    try this:

    PHP Code:
    header('Content-type: application/json');
    echo 
    json_encode($data); 

  3. #3
    SitePoint Enthusiast
    Join Date
    Jan 2007
    Posts
    26
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thats it ??
    its works ^^

    but no need to add also Access-Control-Allow-Origin ?!?!


Tags for this Thread

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
  •