The method for jquery to query the parameters passed by another jsp is: 1. Use the URL query string. The JSP page adds the parameters to the URL query string and uses the `location.search` attribute to obtain the query string. The value that needs to be used; 2. Use POST request, the form submits data through the POST method, and then jQuery uses the "$.post()" method to send the Ajax request, pass the parameters as a JSON object, and process the returned data in the callback function. Can.
Operating system for this tutorial: Windows 10 system, jQuery3.6.0 version, Dell G3 computer.
The way you use jQuery to query the parameters passed by another JSP page depends on how the parameters are passed in the URL.
The following are two common methods:
Method 1: Using the URL query string
The JSP page can add parameters to In the query string of the URL, for example:
http://example.com/mypage.jsp?param1=value1¶m2=value2
Using jQuery to get the value in the query string requires the use of the `location.search` attribute. Here is an example:
// 获取查询字符串 var queryString = window.location.search; // 使用正则表达式分离参数和值 var regex = /[?&]([^=#]+)=([^&#]*)/g, params = {}, match; while (match = regex.exec(queryString)) { params[decodeURIComponent(match[1])] = decodeURIComponent(match[2]); } // 获取参数值 var param1Value = params["param1"]; var param2Value = params["param2"];
Method 2: Using POST request
If you use POST request to submit the form, you can use jQuery's `$.post()` method Send AJAX request:
$.post("otherpage.jsp", {param1: value1, param2: value2}, function(data) { // 处理返回值 });
In the above code, we sent a POST request to `otherpage.jsp` and passed the parameters in the form of JSON object. In the callback function, we can process the returned data.
Either way, it is easy to query the parameters passed by another jsp page through jquery.
The above is the detailed content of How to query parameters passed by another jsp using jquery. For more information, please follow other related articles on the PHP Chinese website!
if($res){
return json_encode(array('code'=>1,'msg'=>'成功'));
}else{
return json_encode(array('code'=>0,'msg'=>'失败'));
}
}
public function
}
if($res){
return json_encode(array('code'=>1,'msg'=>'成功'));
}else{
return json_encode(array('code'=>0,'msg'=>'失败'));
}
}
public function
}
if($res){
return json_encode(array('code'=>1,'msg'=>'成功'));
}else{
return json_encode(array('code'=>0,'msg'=>'失败'));
}
}
public function
}
if($res){
return json_encode(array('code'=>1,'msg'=>'成功'));
}else{
return json_encode(array('code'=>0,'msg'=>'失败'));
}
}
public function
}