简体   繁体   English

用jQuery进行AJAX调用并获得结果

[英]AJAX call with jQuery and get result

jQuery.ajax({
    type: "POST",
    url: "index.php?page=Chat",
    data: { action: "sendMessage" },
}).done(function(msg) {
    jQuery("#main").append(msg);
});

and my PHP code simple returns a string 我的PHP代码简单地返回一个字符串

return 'myString';

Unfortunately myString is not added to the #main-container . 不幸的是, myString没有添加到#main-container What is wrong with this code? 此代码有什么问题?

The OP tried to treat php pages as functions but php pages cannot return value like functions. OP尝试将php页面视为函数,但php页面无法返回类似于函数的值。 Therefore the solution of this question is to print $mystring in php page instead of returning it. 因此,此问题的解决方案是在php页中打印$ mystring而不是将其返回。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM