Specifications
The HTTP API 285
Example
The following code gets the contents of a file on a web server and puts it in a new, untitled
Dreamweaver document:
var httpReply = MMHttp.getText("http://www.dreamcentral.com/¬
people/profiles/lori.html");
if (httpReply.statusCode == 200){
var newDoc = dw.createDocument();
newDoc.documentElement.outerHTML = httpReply.data;
}
MMHttp.getTextCallback()
Description
Retrieves the contents of the document at the specified URL and passes it to the specified
function.
Arguments
callbackFunc, URL
• callbackFunc is the name of the JavaScript function to call when the HTTP request is
complete.
• URL is an absolute URL on a web server; if http:// is omitted from the URL, Dreamweaver MX
assumes HTTP protocol.
Returns
An object that represents the reply from the server. The data property of this object is a string
that contains the contents of the document.
Example
The following code populates a form field with the text that the MMHttp.GetTextCallback()
function returns, or it shows an error message if the function returns an error:
var requestID = MMHttp.getTextCallback("httpCallback", ¬
"www.dreamcentral.com/index.html")
function httpCallback(requestID,reply) {
if (reply.statusCode == 200) {
document.theForm.docContents.value = reply.data;
}else{
alert("Request #: " + requestID + "returned the following ¬
error: " + reply.statusCode);
}
}