Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 513
  • Last Modified:

Help with Jquery/Json

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
Johny Bravo
Asked:
Johny Bravo
  • 4
  • 4
  • 2
  • +1
2 Solutions
 
Monica PSoftware DeveloperCommented:
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
 
Johny BravoAuthor Commented:
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
The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

 
leakim971PluritechnicianCommented:
replace : }).error(function () { alert("error"); })
by : }).error(function (jqXHR, textStatus, errorThrown) { alert(textStatus + "\n" + errorThrown); });
0
 
Johny BravoAuthor Commented:
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
 
Jagadishwor DulalBraces MediaCommented:
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
 
Johny BravoAuthor Commented:
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
 
Jagadishwor DulalBraces MediaCommented:
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
 
leakim971PluritechnicianCommented:
0
 
Johny BravoAuthor Commented:
Adding a MIME type for json on server resolves this issue.
Thanks a lot
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 4
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now