jquery under the Submit, click the button does not respond, the Post method does not perform JSON mode in the form form without effect

Source: Internet
Author: User

When using jquery submission:

(1)

<button id= "Login" > Login </button>
$ (). Ready (function () {
  $ ("#login")
  	. button ()
  	. Click (function () {
        	//alert ("username" +$ ("#userName "). Val ());
  		$.post ("
  	        	checklogin.action",
  			{"username": $ ("#username"). Val (), "Password": $ ("#password"). Val ()},
  			function (data) {
  				//alert (DATA.SUC)
  				if (data.suc) {
  				        window.location.href= "userlist.action";
  			        } else {
  					$ ("#error_message"). HTML ("* The username or password is incorrect.");
  				}
  			,
  			"JSON"		
  	);
 });

(2)
<input type= "image" Src= "Images/btn_login.png" onclick= "Javascript:submitform ()" id= "Btn_log" width= "" height= " /> "
function SubmitForm () {
  if ($ ("#userName"). val () = "")
  	$ ("#error_message"). HTML ("* User Name can not be null.");
  Else if ($ ("#userPassword"). val () = "" "
  	$ (" #error_message "). HTML (" * Password can not be null. "); 			
  else {
  	$.post (
  	        "Checklogin.action",
  		{"username": $ ("#username"). Val (), "Password": $ ("#password"). Val ( )},
  		function (data) {
  		        if (data.suc) {
  			        location.href= "userlist.action";
  		        } else {
  				$ ("#error_ Message "). HTML (" * The username or password is incorrect. ");			
  			}
  		,
  		" json ");
 }	

The above two methods, in HTML, form forms are not allowed to appear

<form method= ""  action= ""////>
    ///////
</form>
Otherwise there is an error (click no response, JS function inside the JSON way POST method is not performed).


Remove,<form></form>




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.