我们的一些合作伙伴在php中开发了一个Web服务,并提供他们的Web服务消费地址,如“http://XXX.XXX.XXX.XX:8081/ExposeWebservices/getLinkByLinkId.php”。现在我们有责任在asp.net应用程序中使用这些服务。为了通过Jquery ajax消费他们的服务,我已经尝试了很多,但我没有运气实现这一点。我试过这种方式:
这是我的jquery代码:
$(document).ready(function () {
$('#btnSearch').click(function () {
var _linkId = $('#txtlinkId').val();
if (_linkId === '') {
alert('please input link id ');
return;
}
// Here LDMAObject is javascript object
var ldma = new LDMAObject(0, _linkId, 'getLinkByLinkId');
var myCallback = function (data) {
alert('callback'+data);
};
$.ajax({
crossDomain: true,
type: "GET",
contentType: "application/json; charset=utf-8",
async: false,
url: "http://XXX.XXX.XXX.XX:8081/ExposeWebservices/getLinkByLinkId.php",
data: { value: ldma.toJsonString() },
dataType: "jsonp",
jsonp: 'callback',
jsonpCallback: myCallback,
success: function (result) { alert('success' +result); },
error: function (url,status,item) { alert('url='+url+'status='+status+'item='+item); }
});
});
});
这是我的LDMAObject.js文件代码:
function generateUUID() {
var d = new Date().getTime();
var uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
var r = (d + Math.random() * 16) % 16 | 0;
d = Math.floor(d / 16);
return (c == 'x' ? r : (r & 0x7 | 0x8)).toString(16);
});
return uuid;
};
function getFormattedDateTime() {
var zero = '0';
var d = new Date();
var curr_date = d.getDate() < 10 ? zero + d.getDate() : d.getDate();
var curr_month = d.getMonth() + 1 < 10 ? zero + d.getMonth() : d.getMonth(); //Months are zero based
var curr_year = d.getFullYear();
var curr_hour = d.getHours() < 10 ? zero + d.getHours() : d.getHours();
var curr_minute = d.getMinutes() < 10 ? zero + d.getMinutes() : d.getMinutes();
var curr_second = d.getSeconds() < 10 ? zero + d.getSeconds() : d.getSeconds();
var curr_milisecond = d.getMilliseconds() < 10 ? zero + d.getMilliseconds() : d.getMilliseconds();
return curr_year + "-" + curr_month + "-" + curr_date + " " + curr_hour + ":" + curr_minute + ":" + curr_second;
}
/* OOP LDMAObject*/
function LDMAObject(flag,linkId,requestFuncName) {
// Object private properties
this.requestHeader = {
requestID: generateUUID(),
requestTime: getFormattedDateTime(),
requestLoginID: '', /* Id and password not given for security reason */
requestPassword: '',
requestFunction: requestFuncName
};
this.requestParam = {
flag: flag,
linkId: linkId
};
this.toJsonString = function () { return JSON.stringify(this); };
}
这是我的HTML:
<div class="myContentDiv">
<div id="form">
<h1>
Search With LinkId :
</h1>
<label>
LinkId :
</label>
<input type="text" name="txtlinkId" id="txtlinkId" />
<input id="btnSearch" type="button" value="Search" />
<div class="spacer">
</div>
<div id="lbl">
</div>
</div>
</div>
有人请帮助我。我正处于视频群聊模式。你的帮助将从心底接受。