Jump to content

  • Log In with Google      Sign In   
  • Create Account

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


Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.


  • You cannot reply to this topic
2 replies to this topic

#1 Nymall   Members   -  Reputation: 202

Like
1Likes
Like

Posted 22 February 2013 - 11:25 AM

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, 22 February 2013 - 01:27 PM.

My favorite error yet:

Parse error: Syntax error, unexpected '$pants'...


#2 EmployeeNumber8   Crossbones+   -  Reputation: 1103

Like
0Likes
Like

Posted 22 February 2013 - 12:53 PM

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.



#3 Havsmonstret   Members   -  Reputation: 689

Like
0Likes
Like

Posted 22 February 2013 - 02:29 PM

Edit: Didn't read closely enough.


Edited by Navall, 22 February 2013 - 02:30 PM.





Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.




PARTNERS