JS code {code...} HTML code {code...} PHP code {code...} ① the result can only get an empty Array (). why? Question 2: What is the role of the name attribute in the $. get method? JS code
$.get("test.php",{ Xiaopeng : $("#selectbtn1").text() },function(data,textStatus){ $("#right-table").load("test.php"); })
HTML code
PHP code
① Only one empty Array () can be obtained ()
Why? Search for confusion
② I also want to ask what role the name attribute plays in the $. get submission method.
?
Reply content:
JS code
$.get("test.php",{ Xiaopeng : $("#selectbtn1").text() },function(data,textStatus){ $("#right-table").load("test.php"); })
HTML code
PHP code
① Only one empty Array () can be obtained ()
Why? Search for confusion
② I also want to ask what role the name attribute plays in the $. get submission method.
?
The train of thought is wrong, or you do not have a good understanding of the $. get and $ (element). load methods.
$.get('test.php', {Xiaopeng: 'text'}, function(data){ console.log(data); });
In this case, the actual request address is test. php? Xiaopeng = text, but the returned data is not empty,
$("#right-table").load("test.php");
This sentence means to get the content returned by test. php and put it in # right-table. at this time, the parameter Xiaopeng = text does not exist, so we can only get an empty array.
The following two methods are positive solutions:
// Method 1 $. get ('test. php', {Xiaopeng: 'text'}, function (data) {$ ("# right-table" ).html (data );}); // method 2 $ ("# right-table "). load ('test. php? Xiaopeng = '+ $ ("# selectbtn1"). text ());
We recommend that you use Firefox (which requires the firebug plug-in) or the chrome browser and use the corresponding functions to detect ajax requests. you will find that your original code has sent two different requests, the returned value of the second request that you output, and the second request does not have any data to be sent.
Xiaopeng
Put Xiaopeng in class
Xiaopeng
Then obtain
$(".Xiaopeng").text()
I always think that your implementation method is very strange. you can describe your requirements and try to solve them.
Alert or console. log () $ ("# selectbtn1"). text () to see if the value is correctly obtained