开发者

pass data using jquery $.get()

开发者 https://www.devze.com 2023-04-10 15:49 出处:网络
I try to implement the following code: html <span id = \"myset\">school</span> Javascript var myset =$(\"#myset\").val();

I try to implement the following code:

html

   <span id = "myset">school</span>

Javascript

      var myset =$("#myset").val();
        var ID=$("#data li:last").attr("id");
    $.get('page.php', 'id='+ID+'&set='+myset, function(newdata){
        $('#data').append(newdata);

    });

In the page.php file, it doesn't receive the value of the $_GET['set'], but if I change

      var myset =$("#myset").val();

to:

       var myset ='school';

everything works fine in this case, what am I doing wrong, anyone could help me, thanks. I also tried

       var myset =document.getElementById("myset"开发者_C百科).value;

but it is still not working;


Span tags don't have a value, they have .innerText or .innerHTML or, with jQuery, .html() or .text()


"school" isn't the value of your span. It is the data of a text node inside your span. You can access it like this:

var myset = $("#myset").text();


Use var myset =$("#myset").text(); instead.

0

精彩评论

暂无评论...
验证码 换一张
取 消