开发者

Is it valid to define function(json) and if yes what does it mean? [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.
    $.getJSON(link,function(json)
       {
            if( json.length> 0)
       {

document.form_reserve.action ="http://localhost/ReserveRoomsBackend.php?        

bldg_number="+json[0].bldg_number +" & room_number="+json[0].room_number;
        document.getElementById("form_reserve").style.display = "block";
    }
             else
       {
      开发者_如何学Go     document.getElementById("label").style.display = "block";
       }

alert("inside json finction" + json.length+"  "+json[0].room_number+"   "+json

[0].bldg_number);
        }); //.getJSON

    }//doAjaxPost


it's just an argument. The function expects ONE argument which is a JS object that jQuery has evaluated from a JSON string.

You're potentially confused by the fact that the { is on the next line, but it's the same as:

function(whatever){


You are calling the function $.getJSON (part of jQuery I guess) with an anonymous function as second parameter/argument (as a callback in this situation). Those anonymous functions are like "normal" functions, they just don't have a name and since you pass this function to getJSON as a reference, jQuery is able to call your function. So, yes it's valid. If this is what you meant.


In this context, json is a parameter passed to a function object, so yeah it's fine (although it's not very representative of the objects content) - it could be named anything.

In this case it could be called "rooms", and you would could call rooms[0].room_number instead of json[0].room_number.

For example, in this case "message" is the name of the parameter:

showAlertDialog("This an example");

function showAlertDialog(message) {
    alert("Your message was:" + message);
}

"json" is often used as the name for the response object in jQuery examples (as it is in your case here).

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜