For ajax problems, please wait online. thank you!

Source: Internet
Author: User
For more information about ajax, see online. thank you for choosing index. php. The page has two p IDs: p1 and p2. the corresponding event is:
$.ajax({url: test.php,type: 'post',dataType:'text',success: function (responseText) {$('#p1').html(responseText);$('#p2').html(responseText);}});

Is there a way to put the values returned from the test. php page to p1 and p2 respectively? What I think is to use js to split the returned value and put it in it. there is no practice yet. I don't know if it works. if it works, I don't think it looks good. Is there any other method?


Reply to discussion (solution)

Yes, but pay attention to it.

ResponseText

It cannot contain the character you want to cut.


We recommend that you use json, which is more convenient. This will not involve cutting.

Yes, but you have to have a unique cutting mark?
Otherwise, the text will be cut, and it will not be beautiful.

Generally, json is used to return multiple data.

$ Res = array ('p1' => 'Related Content', 'P2' => 'Related Content',) echo json_encode ($ res );

$.ajax({  url: 'test.php',  type: 'post',  dataType:'json',  success: function (data) {     $('#p1').html(data.p1);     $('#p2').html(data.p2);  }});

More general
$.post('test.php', {}, function(d) {  for(var i in d) $('#'+i).html(d[i]);}, 'json');

Yes, but pay attention to it.

ResponseText

It cannot contain the character you want to cut.


We recommend that you use json, which is more convenient. This will not involve cutting.


Why does "cannot contain the character you want to cut ."? For example, the "People's Republic of China {|} and People's Republic of China (central China)" that I got must have {|.

Yes, but pay attention to it.

ResponseText

It cannot contain the character you want to cut.


We recommend that you use json, which is more convenient. This will not involve cutting.


Okay. let me try it first.

Yes, but pay attention to it.

ResponseText

It cannot contain the character you want to cut.


We recommend that you use json, which is more convenient. This will not involve cutting.


The last response is to reply to you. haha, it is successful. thank you.


Yes, but pay attention to it.

ResponseText

It cannot contain the character you want to cut.


We recommend that you use json, which is more convenient. This will not involve cutting.


Why does "cannot contain the character you want to cut ."? For example, the "People's Republic of China {|} and People's Republic of China (central China)" that I got must have {|.



If you want to cut by "|", you are right:

// It is obviously correct
This is the test data | this is the test data

// This is incorrect.
This is | test | data | this is | test | data

So you should use json for convenience.

Json, root? Key? Get value ,?? This is convenient.

Basically, I agree that using json key-value pairs can solve many problems that are easier to use than text.

Yes, but you have to have a unique cutting mark?
Otherwise, the text will be cut, and it will not be beautiful.

Generally, json is used to return multiple data.

$ Res = array ('p1' => 'Related Content', 'P2' => 'Related Content',) echo json_encode ($ res );

$.ajax({  url: 'test.php',  type: 'post',  dataType:'json',  success: function (data) {     $('#p1').html(data.p1);     $('#p2').html(data.p2);  }});

More general
$.post('test.php', {}, function(d) {  for(var i in d) $('#'+i).html(d[i]);}, 'json');


It's strange that I replied twice, but I quoted you and changed it to the first one.


Yes, but you have to have a unique cutting mark?
Otherwise, the text will be cut, and it will not be beautiful.

Generally, json is used to return multiple data.

$ Res = array ('p1' => 'Related Content', 'P2' => 'Related Content',) echo json_encode ($ res );

$.ajax({  url: 'test.php',  type: 'post',  dataType:'json',  success: function (data) {     $('#p1').html(data.p1);     $('#p2').html(data.p2);  }});

More general
$.post('test.php', {}, function(d) {  for(var i in d) $('#'+i).html(d[i]);}, 'json');


It's strange that I replied twice, but I quoted you and changed it to the first one. Perfect solution. thank you.

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.