开发者

How do I get data back from php call using Jquery.form.js?

I am using the AjaxForm() call from jquery.form.js to attempt to run a php script that will put data into the data base and then pull it out. But how would you make that call using the ajaxForm call from jquery.form.js?

*UPDATE: ADDED SOME CODE *

    $('#profilepicbutton').live('change', function(){
    $("#preview").html('');
    $("#preview").html('<img src="loader.gif" alt="Uploading...."/>');
        $("#registerpt3").ajaxForm({target: '#preview'}).submit();
        /*$.post(
        "register3.php",{
            target:'#preview'},
            function(data){*/
                $("#preview").html('');
                $("#preview").append("<img src="+data+"></img>");
 });

My PHP code...

    if(isset($_POST) and $_SERVER['REQUEST_METHOD'] == "POST")
    {
  $name = $_FILES['profilepicinput']['name'];
  $size = $_FILES['profilepicinput']['size'];
  if(strlen($name))
  {
    list($txt, $ext) = explode(".", $name);
    if(in_array($ext,$valid_formats))
    {
        if($size<(1024*1024)) // Image size max 1 MB
        {
            $actual_image_name = time().$session_id.".".$ext;
            $tmp = $_FILES['profilepicinput']['tmp_name'];
            $fp      = fopen($tmp, 'r');
            $data = fread($fp, filesize($tmp));
            $data = addslashes($data);
            fclose($fp);
            if(mysql_query("insert into Personal_Photos (Email, Pics) values('$email', '$data')"))
            {
                $query="select Pics, MAX(ID) from Personal_Photos where Email='$email'";
                $result=mysql_query($query) or die("Error: ".mysql_error());
                $row=mysql_fetch_array($result);
                header("Content-type: image/jpg");
                print($row['Pics']);
            }
            else
            {
                die('Invalid query: ' . mysql_error());
                echo "failed";
            }
        }
        else
            echo "Image file size max 1 MB. Image Size:"+$size;
    }
    else
        echo "Invalid file format..";
}
else
    echo "Please select image..! Bull shit".$email;
exit;

}

So you are saying that the data should come right back auto-magically?

When I call ajaxForm should I call a function?

UPDATE: Request for an example

hello there. I don't want to be that dude that is constantly asking for example code, but does any body have an example of making an ajaxForm() call and successfully getting data back and posting it to there page? I can't figure out what to do... What I just tried is

$('#profilepicbutton').live('change', function(){
    $("#preview").html('');
    $("#preview").html('<img src="loader.gif" alt="Uploading...."/>');
        $("#registerpt3").ajaxForm({
                target: '#preview',
                success: function(data)
                {                                   
                    $("#preview").html('');
                    $("#preview").append("<img src="+data+"开发者_Go百科></img>");
                }
            }).submit();
 });

When I use firebug to figure out what is in data, it is telling me that it is undefined. Really confused. Please help.


You simply do: $('#myFormId').ajaxForm(); and it should auto-magically work :) You can pass any of the standard $.ajax options to ajaxForm (complete and success callbacks, etc).

You can see the complete docs here: http://jquery.malsup.com/form/#getting-started

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜