Using JS $(this).attr('action'); in Html cannot get the value
品茗坐看风吹雨
品茗坐看风吹雨 2018-03-21 14:21:21
0
4
1833

I have just been exposed to PHP for a short time, and I am a novice. Now I am stuck and I can’t find a solution online.

Now I want to implement a simple function: use ajax in Html to pass variables to the test2 method in PHP.
---
thinkphp 3.2.3, ajax submission, php function processing

Problem: Unable to read attributes in action

<div> ;
<form id="form1" method="post" action="{:U('Home/Test/Test2')}">
<br>Table Name:<br>
                                                                                                                                                                                              ## </form>
</div>

##<script>

function login() {

var Tbname = $( '#Tbna').val();
      alert(Tbname);

    var url = $(this).attr('action'); //changePassword method under the Index controller
alert(url);

$.ajax({
type:"post", //Submission method

url:url, //Submit address

                                                                                                                                                                                                                                                                                                       success ;//                                                                                   000});//             }
}
});
return false;
};

</script>

品茗坐看风吹雨
品茗坐看风吹雨

reply all(1)
sky

var url="{:U('Home/Test/Test2')}";

Isn’t this the end?

  • reply It's OK to write it directly, but I want to know why attr doesn't work.
    品茗坐看风吹雨 author 2018-03-21 15:38:10
  • reply $this gets the button click, so attr does not work
    sky author 2018-03-21 15:46:00
  • reply Oh, thank you. Newbies can learn from this, thank you
    品茗坐看风吹雨 author 2018-03-25 12:06:14
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template