I'm sending a post request to a php file that makes an MySQL query and iterates through the responses. During the iteration it echo's out a string that I want to bring into jquery one-by-one for each iteration.
So for each echo I would like one success value so that the user does not have to wait for all the iterations to finish.
The class compSelect is a select element.
I'd like for the option to be appended as the echo's come in msg by msg, not all in one msg.
Right now the msg on success looks like name1name2name3
I would like each msg to be an individual name.
The JavaScript
$.ajax({
type: "POST",
cache: false,
url: "class.GetMiscInfo.php",
data: "getNames=1&name=Jack",
dataType: "html",
success: function(msg) {
$('.compSelect').append("<option value='" + msg +"'>" + msg +"</option>");
}
});
The PHP/MySql
class GetMiscInfo
{
public static function getNames($name)
{
$res = mysql_query("SELECT names.name FROM names WHERE names.name='$name'");
while($row = mysql_fetch_assoc($res))
{
echo $row['name'];
}
}
}
if(isset($_REQUEST['getNames']))
GetMiscInfo::getNames($_REQUEST['name']);
I know I can separate them with a string like ~ and then just split the responses, but for more complicated queries I would like to not have to wait.
I think I'm just missing some knowledge related to Ajax to get what I want.