开发者

Why is my json response a page full of source code

开发者 https://www.devze.com 2023-03-23 06:24 出处:网络
I have a simple checkbox, on click it sends XHR to PHP page , php processes correctly and I use json_encode($response) to return. But instead of a simple true or false I get the source code for the pa

I have a simple checkbox, on click it sends XHR to PHP page , php processes correctly and I use json_encode($response) to return. But instead of a simple true or false I get the source code for the page and it is causing a "parsererror" of course. ajax call as follows

$.ajax({
type: "post",
url: "myprocessor.php",
dataType: 'json',
data: { "id" : idnumber, "action": "makeLive", "isLive" : "1" },
beforeSend: function(data) {
            $("#ajaxInProgress").addClass('progress');
        },
        success: function(data) {
            $("#status").removeClass().addClass((data.error === true) ? 'error' : 'success').text('Success! Appraiser is NO LONGER Live ').slideDown('slow');
        },
        error: function(data) {
            $("#status").removeClass().addClass('error').text(' - Changing the Live status for this appraiser to "Not Live" has failed - APPRAISER IS STILL LIVE IN SYSTEM, please try again').slideDown('slow');
        },

        complete: function(data) {
            $("#ajaxInProgress").removeClass('progress');
            setTimeout(function() {
                $("#status").slideUp('slow').removeClass();
            },2000);
        }
    }); 

The php I post to is as follows:

if (isset($_POST['action'])) { 
if($_POST['action']=='makeLive') { 
    $checkappraiser=mysql_query("SELECT * FROM table WHERE id='".mysql_real_escape_string($_POST['id'])."'");
    if (mysql_numrows($checkappraiser)>0) {
        $livesetting=mysql_result($checkappraiser,0,"live");
        $livesetting=!$livesetting;
        $runSql = mysql_query("UPDATE table SET live='$livesetting' WHERE id='".mysql_real_escape_string($_POST['id'])."'");
        if(!$runSql) {
            $return['error'] = true;
        } else { 
            $return['error'] = false;   
        }
    }
}   
echo json_encode($return);
}

Any suggestions would be great. I开发者_JAVA百科 am getting the proper data passed I am getting the correct data updated in DB My response is coming back as a parser error because it is trying to parse the source code as a json array.


Just a quick check, do you put <?php at the beginning of your php file?


That, or you're doing something wrong in your webserver, not passing files through to php correctly. Does hitting the php file directly load the source or the result?

If you hit page.php, does it load the same thing as if you hit page.phP or pHP, etc? It matters to web server filters, depending on the web server...

If you use tomcat for java, for example... you can turn off case sensitivity for finding files, but it does not turn off case sensitivity for mapping files to filters or servlets, so .jsp would load the jsp servlet, but .jsP would not.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号