Does javascript-$. get send data to the PHP page but cannot receive it?

Source: Internet
Author: User
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

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.