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.