Sign in to follow this  
Nymall

Javascript/Jquery strange errors, trying to get %22 and %7B?

Recommended Posts

Nymall    202
UPDATE: I've discovered the problem, and now I feel foolish. I accidentally removed the JSON parsing, and for one reason or another tried to re-implement it by accessing it as a array. It's one of those mistakes that is done at 1am on a saturday, and never rediscovered. Thank you for responding, though!
 
Hey guys,
 
I've been working on a project for my wife in my free time, a type of adventure game in PHP. She's been doing the writing, and as I've been a dabbling programmer for many years I've taken up the mantle of developer.
 
The game is written in PHP, and it's using Javascript and Jquery to dynamically get data from the PHP script through JSON and enact changes on the page dynamically. For quite a while, development has been going good and it was almost playable for a short period of time... then, this happened:

 

GET http://127.0.0.1/New%20Pointless/%7B 404 (Not Found) jquery-1.9.1.js:2358
GET http://127.0.0.1/New%20Pointless/%22 403 (Forbidden) jquery-1.9.1.js:2358


 

The data from the php script is JSON, and I've confirmed that it's being sent properly, and I have error suppresion on that side so it's not throwing a monkey wrench in the works... I'm really not sure why this is happening. I've done SEVERAL hours of investigation on these errors, and I haven't the foggiest clue why they exist.
 
I've gone to the area quoted by the chrome console, and it appears to be in the .attr function of jquery. The thing is, there are no get commands called by the javascript for either %7B or %22. I took a guess that they might be rogue characters, but I can't find anywhere in the javascript where " and { are sent via get.
 
Here's the javascript code as it stands:
 
<script language="javascript">
function onstart(){
    loadbyref('S00010000');
    $('#text').hide();
    $('#textfill').hide();
}
function loadbyref(LocByRef) {
    $.post('game.php',                  //the script to call to get data          
      {
        atr:LocByRef
      },
      function(data)          //on recieve of reply
      {
        var background = data[0];
        var convo = data[1];
        var convotext = data[2];
        var people = data[3];
        var buttonone = data[4];
        var buttontwo = data[5];
        var buttonthree = data[6];
        var islocation = data[7];
        var personlink = data[8];
        var buttonoutput = "";
        $('#gamescreen').attr("src", background);
        if(convo!=true){
            $('#text').hide();
            $('#textfill').hide();
            if(people!="nil"){
                $('#people').show();
                $('#people').attr("src", people);
                $('#people').attr("onClick", personlink);
            }else{
                $('#people').hide();
            }
        }else{
            $('#people').show();
            $('#people').attr("src", people);
            $('#text').show();
            $('#textfill').show();
            $('#textplace').html(convotext);
            if(buttonone!='nil'){
                buttonoutput = buttonone;
            }
            if(buttontwo!='nil'){
                buttonoutput += buttontwo;
            }
            if(buttonthree!='nil'){
                buttonoutput += buttonthree;
            }
            $('#buttonfill').html(buttonoutput);
        }
      } 
    );
}
 

 

 
 
And here is the example of the response from the php script:
 
 

 

{"0":"mydorm.png","1":false,"2":"nil","3":"nil","8":"nil","4":"nil","5":"nil","6":"nil","7":true}

 

 

 
Is there something obvious I'm missing? Any help would be appreciated!
Edited by Nymall

Share this post


Link to post
Share on other sites
DangerDoom    1103

Check all of the src attributes that get updated. One of them is most likely the culprit.

In the callback function, it looks as if you set the src property of a few elements. Debug using the chome dev tools again and set a breakpoint somewhere inside that callback. Just examine the src of every element as it gets updated. 

 

like this one:

 

$('#people').attr("src", people);

Or just step through the code by pressing F10, and then see which one causes the error.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this