send parameter to Java Server Pages (JSP) using jQuery

别来无恙 提交于 2020-01-04 15:59:11

问题


I want to send different parameters to JSP. Is it possible to send multiple parameter to JSP in jQuery? Because jQuery is client side and JSP is server side.

Update me!


回答1:


You can make an ajax request passing parameters

For example:

$.ajax({
  type: "POST",
  url: "userNameCheck.jsp",
  data: { username: "John"}
}).done(function( msg ) {
  alert( msg );
  //do other processing
});

See

  • jQuery.ajax



回答2:


Simplest case: you want to open some page with javascript (jQuery). In this case you can send parameters in request to page:

document.location.href = "http://yourdomain.com/yourpage.jsp?paramName=" + paramValue;

If you need to send data without page reloading use ajax as Jigar say.




回答3:


You can do like this:

$.ajax({
                    type: "POST",
                    url: "yoursite.com",
                    contentType: "application/json; charset=utf-8",
                    data: {param1: value1 , param2: "value2", param3: "value3"},
                    dataType: "json",
                    success: Succeess,
                    error: Failed
                });


来源:https://stackoverflow.com/questions/10752496/send-parameter-to-java-server-pages-jsp-using-jquery

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!