Jump to content

PHP/AJAX Question - (PHP Upload)


tarun

Recommended Posts

I Have A PHP Upload Script

 

 

It Works Fine When Uploading Using A Form

But I Doesn't Work When Creating An AJAX Post

 

 

Why...?

Is What I Would Like To Know

And If Possible How Can I Correct It

 

 

 

I Do Not Which To Display The Contents Of The PHP Script But The AJAX/HTML Is Fine

 

 

<script>
var page = "upload.php";
function postAJAX(url, query, target)
{
    var status = false;
    var contentType = "application/x-www-form-urlencoded; charset=UTF-8";

    // Native XMLHttpRequest object
    if (window.XMLHttpRequest) {
        request = new XMLHttpRequest();
        request.onreadystatechange = function() {ajaxDone(target);};
        request.open("post", url, true);
        request.setRequestHeader("Content-Type", contentType);
        request.send(query);
        status = true;

    // ActiveX XMLHttpRequest object
    } else if (window.ActiveXObject) {
        request = new ActiveXObject("Microsoft.XMLHTTP");
        if (request) {
            request.onreadystatechange = function() {ajaxDone(target);};
            request.open("post", url, true);
            request.setRequestHeader("Content-Type", contentType);
            request.send(query);
            status = true;
        }
    }

    return status;
}



function ajaxDone(target) {
if (request.readyState == 4) {
	if (request.status == 200 || req.status == 304) {
		results = request.responseText;
		document.getElementById(target).innerHTML = results;
		}
		else {           document.getElementById(target).innerHTML="Ajax Error:\n" + req.statusText;
		}
	}
}
</script>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.