1

我正在尝试上传文件而不重新加载或将页面重定向到其他页面。
我试过了...

upload.php

<form enctype='multipart/form-data' action='/' method='POST' class="AjaxSubmit" id='newwork' name='newwork'>
    Choose New Work<br />
    <input name='uploadednewwork' type='file' /><br />
    <button id="btnFrmPost1" class="button" onclick="up()" >New Work</button>
</form>

脚本.js

    function up() {  
  $('#btnFrmPost1').click(function() { 
            event.preventDefault();
            var $form = $(this);
            var url = "/subpages/upload_new_work.php";
            var data = $form.serialize()
            $.ajax({
                type: "POST",
                dataType: "json",
                url: url,
                data: data,
                success: function (resp) {
                    var jdata = eval(resp);
                    var $jAlrtSuccess = $('<div>' + jdata.responseText + '</div>');
                    $($jAlrtSuccess).dialog({modal:true});
                },
                error: function (xhr, status, error) {
                    var $jAlrtError = $('<div>' + xhr.responseText + '</div>');
                    $($jAlrtError).dialog({modal:true});
                }
            });
        return false;
    });
   }

我已经尝试了所有这些代码......
但我不会得到结果......
谁能告诉我如何解决这个问题......

4

0 回答 0