开发者

What is the easiest way to get an echoed or returned string from php into jquery/ajax

Let's say that I have in my test.php:

echo 'Hello, world'

And I want to place th开发者_如何学JAVAat text in a div.

This doesn't work for me and the alert also does not pop out.

$.ajax({
   type: "GET",
   url: "test.php",
   data : data,
   success: function(msg){
     alert('Does it Work?');
     ("#div_1").html(message);
 });


$.get('test.php',function(data) { alert('data:'+data); });


The easiest way is to use the load function:

$("#div_1").load("test.php", data);

This places the HTML output from test.php directly into the #div_1 element.


You have a syntax error, that may be the issue (you forgot to close a curly bracket and a parenthesis). Try

$.ajax({
    type: "GET",
    url: "test.php",
    data : data,
    success: function(msg){
      alert('Does it Work?');
      $("#div_1").html(message.txt);
    }
});


$.ajax({
   type: "GET",
   url: "test.php",
   data : data,
   success: function(msg){
     alert(msg);
     $("#div_1").html(msg);
   }
 });
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜