在JSP中代码如下:
function sendRequest(param, callback){
var myAjax = new Ajax.Request('/eGMAjax.do',{method:'post',parameters:param,onFailure:showOpenFail,onComplete:callback});
}function requestData() {
var param='txcode=getChipOdds&city='+city;
sendRequest(param, setAllDatas);
} 现在Delphi通过idhttp或ixmlhttprequest实现类似功能,应怎样做?
function sendRequest(param, callback){
var myAjax = new Ajax.Request('/eGMAjax.do',{method:'post',parameters:param,onFailure:showOpenFail,onComplete:callback});
}function requestData() {
var param='txcode=getChipOdds&city='+city;
sendRequest(param, setAllDatas);
} 现在Delphi通过idhttp或ixmlhttprequest实现类似功能,应怎样做?
对比一下,就明白了。能理解好多东西。
begin Url:=TStringList.Create;
Url.Add('usernames='+DataM.ADQTrans.FieldByName('name').AsString);
Url.Add('hosname='+DataM.ADQTrans.FieldByName('hosname').AsString);
Url.Add('doctors='+DataM.ADQTrans.FieldByName('doctors').AsString);
Url.Add('caller='+Phone);
Url.Add('send_mobile='+DataM.ADQTrans.FieldByName('send_mobile').AsString);
Url.Add('result='+DataM.ADQTrans.FieldByName('result').AsString);
Url.Add('send_time='+DataM.ADQTrans.FieldByName('send_time').AsString);
http.Post('http://123.123.123.123/rec.asp',Url);
end;
http := CreateOleObject('Microsoft.XMLHTTP') as IXMLHTTPRequest;
http.open('POST', 'http://liujc-w/eGMAjax.do', false, 'a', '1');
http.setRequestHeader('Content-type', 'text/html; charset=UTF-8');
http.send('txcode=doChip&method=0);
但看到服务器中通过String method = request.getParameter("method")接收到的参数值都为null,用上面那样的写法是可以收到,不知为何?
ExtCtrls, Classes, ComObj, MSXML2_TLB,type
TAjaxService = class
private
F_XmlHttp : IXMLHTTPRequest;
public
constructor Create;
destructor Destroy; override;
function HttpExchange(xmlstr: string; content_type, url: string):string;
end;implementationconstructor TAjaxService.Create;
begin
F_XmlHttp := CreateOleObject('Microsoft.XMLHTTP') as IXMLHTTPRequest;
end;destructor TAjaxService.Destroy;
begin
inherited;
end;function TAjaxService.HttpExchange(xmlstr: string; content_type, url: string): string;
begin
F_XmlHttp.Open('POST', url, false, '', '');
F_XmlHttp.SetRequestHeader('Content-type', content_type);//'text/xml; charset=utf-8'
F_XmlHttp.Send(xmlstr);
Result := F_XmlHttp.responseText;
end;end;....
var
ajax: TAjaxService;
begin
ajax = TAjaxService.Create;
xmlresp := ajax.HttpExchage('', 'text/html',
'http://liujc-w/eGMAjax.do?txcode=getChipOdds&city='+city);
...
end;