$(document).ready(function(){ //The following 3 parameters are required for reservation registration var name = "name"; //varchar type, with a maximum length of 8 digits (4 Chinese characters) var phone = "phone"; / /varchar type, length is 11 digits var addr = "addr"; //varchar type, length is up to 500 digits (250 Chinese characters) $.getJSON("http://request website address/data .php?ac=yuyue_interface&name=" name "&phone=" phone "&addr=" addr "&callback=?", function(data){ if(data.code==1){ //Customized Code alert("Name cannot be empty"); }else if(data.code==2){ //Custom code alert("Mobile phone cannot be empty"); }else if(data.code==3){ //Customized code alert("The unit cannot be empty"); }else{ //Customized Code alert("Appointment successful"); } }); });
It should be noted that in the back-end php code, it must Also output the " &callback=? " passed in, such as:
The above is one A simple $.getJSON test. Through this test, we can learn how to use $.getJSON and how to make an interface to allow others to make cross-domain requests.