search

Home  >  Q&A  >  body text

Using JS $(this).attr('action'); in Html cannot get the value

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>

品茗坐看风吹雨品茗坐看风吹雨2440 days ago1835

reply all(4)I'll reply

  • sky

    sky2018-03-21 15:22:05

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

    Isn’t this the end?

    reply
    0
  • 品茗坐看风吹雨

    It's OK to write it directly, but I want to know why attr doesn't work.

    品茗坐看风吹雨 · 2018-03-21 15:38:10
    sky

    $this gets the button click, so attr does not work

    sky · 2018-03-21 15:46:00
    品茗坐看风吹雨

    Oh, thank you. Newbies can learn from this, thank you

    品茗坐看风吹雨 · 2018-03-25 12:06:14
  • Cancelreply