Solved

Help with Jquery/Json

Posted on 2013-06-22
11
499 Views
Last Modified: 2013-06-24
Hi Experts,

I am building a quiz system.

I have implemented the quiz referring below,
http://www.meredithdodge.com/2012/03/16/tutorial-easy-jquery-based-quiz/

This works on my machine very well, but on production server it is throwing error,

//Load json file
function getData(update) {

    alert(jsonpath + jsonfile);
    $.getJSON(jsonpath + jsonfile, function (json) {
        //Execute the callback
        alert("in");
        update(json);
    }).error(function () { alert("error"); });
}


It given alert here,     alert(jsonpath + jsonfile);
but then it alerts "error"

Why it is not working on production. Also on blog there are comments that it is not working on server.

Is there something to change on production?
Your assistance is much appreciated. Thanks
0
Comment
Question by:johny_bravo1
  • 4
  • 4
  • 2
  • +1
11 Comments
 
LVL 10

Expert Comment

by:Monica P
ID: 39267825
if you want to know Error message then you can use Firebug in firefox or

Hit F12 or Ctrl+Shift+I Then go to Console tab to check for the Errors
0
 
LVL 82

Expert Comment

by:leakim971
ID: 39268000
0
 
LVL 8

Author Comment

by:johny_bravo1
ID: 39268303
Hi leakim971,

Cross browser scripting... hmm well may be I am not getting the point, but my js and page is on same site.

For reference I am giving the js file below

/*!
* Easy jQuery-Based Quiz ~ Copyright (c) 2012 Meredith Dodge, http://meredithdodge.com
* Released under MIT license
*/

//The path to your images
var imgpath = "images/";
//The path to your json
var jsonpath = "json/";
//The filename will be determined by the rel attribute on div#quiz
var jsonfile = "";

$(document).ready(function () {
    //Make sure radio buttons are not disabled or checked (helpful when refreshing)
    $("input[type='radio']").attr("disabled", false);
    $("input[type='radio']").attr("checked", false);
    $(".submit").click(function (e) {
        e.preventDefault();
        //Check the quiz results
        checkQuiz();
    });
    //Build the json filename
    jsonfile = $("#quiz").attr("rel") + ".json";
});

//Load json file
function getData(update) {
    $.getJSON(jsonpath + jsonfile, function (json) {
        //Execute the callback
        update(json);
    }).error(function () { alert("error"); });
}

function checkQuiz() {
    $(".submit").remove();
    getData(function (data) {
        var ans = data.key;
        var result = {};
        $(".question").each(function () {
            //Get the question id
            var _q = $(this).attr("id");
            //Get the selected answer class
            var _a = $("#" + _q + " input:checked").closest("li").attr("class");
            //Add the values to the result object
            result[_q] = _a;
            //Indicate the correct answer
            $("#" + _q + " ." + ans[_q]).append("<img src='" + imgpath + "circle.png' class='png_bg' alt='correct answer'>");
            //Compare the selected answer with the correct answer
            if (ans[_q] == _a) {
                $(this).addClass("correct");
            } else {
                $(this).addClass("wrong");
            }
        });
        //Build the feedback
        var fdbck = "You got " + $(".correct").length + " out of " + $(".question").length + " correct. "
        if ($(".correct").length == 0) {
            fdbck += "Better luck next time.";
        } else if ($(".correct").length > $(".question").length / 2) {
            fdbck += "Good job!";
        } else {
            fdbck += "Not bad.";
        }
        $(".feedback").text(fdbck);
        $(".feedback").show();
    });
}

Open in new window

0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
LVL 82

Accepted Solution

by:
leakim971 earned 250 total points
ID: 39268505
replace : }).error(function () { alert("error"); })
by : }).error(function (jqXHR, textStatus, errorThrown) { alert(textStatus + "\n" + errorThrown); });
0
 
LVL 8

Author Comment

by:johny_bravo1
ID: 39269257
Hi leakim971,

Thanks

replacing line now gives error "Error Not Found".
Is it like json is missing? while checking of ftp it is present at that location.

If I put the path in url like,
http://www.******.com/User/json/31.json
Getting error,

HTTP Error 404.3 - Not Found
The page you are requesting cannot be served because of the extension configuration. If the page is a script, add a handler. If the file should be downloaded, add a MIME map.

Any suggestion?
0
 
LVL 15

Assisted Solution

by:Jagadishwor Dulal
Jagadishwor Dulal earned 250 total points
ID: 39270139
That is file not found error and you can check for your reference json file. Can you access your json file using url?? Manage the url.
0
 
LVL 8

Author Comment

by:johny_bravo1
ID: 39270347
No I can't access json through url.
Getting error:
"HTTP Error 404.3 - Not Found
The page you are requesting cannot be served because of the extension configuration. If the page is a script, add a handler. If the file should be downloaded, add a MIME map."

Contacted to hosting team regarding, if it is an issue with mime type. Will update you.
Thanks
0
 
LVL 15

Expert Comment

by:Jagadishwor Dulal
ID: 39270423
Are you calling this page in serverside script?? Other wise you should confirm the file location and extension. It can .js file or .json file.
0
 
LVL 82

Expert Comment

by:leakim971
ID: 39270465
0
 
LVL 82

Expert Comment

by:leakim971
ID: 39270513
0
 
LVL 8

Author Closing Comment

by:johny_bravo1
ID: 39271170
Adding a MIME type for json on server resolves this issue.
Thanks a lot
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Requirements JQuery 1.6+ HTML CSS Introduction This article was inspired by an EE question (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28372511.html) on how to make a page show some balloons animate up a page…
How to build a simple, quick and effective accordion menu using just 15 lines of jQuery and 2 css classes
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…

805 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