我正在使用AJAX从PHP构建的Web服务请求一些信息,但是我传递的参数似乎没有转到我的代码所在的Web服务:
$(document).on( "pageinit", "#player", function( e ) {
var passedId = (passDataObject.selectedHref != null ? passDataObject.selectedHref : window.location.href).replace( /.*id=/, "" );
alert(passedId); // test passedId has the correct value within it
var surl = "a working url";
$.ajax({
type: "GET",
url: surl,
data: "&Track="+passedId,
dataType: "jsonp",
cache : false,
jsonp : "onJSONPLoad",
jsonpCallback: "trackcallback",
crossDomain: "true",
success: function(response) {
alert('tracks function');
},
error: function (xhr, status) {
alert('Unknown error ' + status);
}
});
});
//callback function for player page
function trackcallback(rtndata)
{
alert(rtndata.track_name); // show up as undefined
}
passId在其中具有正确的值,并且URL很好,但即使SQL语句正常,Web服务也不会产生结果。我假设问题是在我的php web服务$id = $_REQUEST['Track'];
中的这一行内,因为它从JavaScript获取执行SQL的值。
任何人都可以解决这个问题吗?
答案 0 :(得分:0)
请参阅下面的代码,没有“&”在参数名称之前:
$.ajax({ url: homeUrl + "/Getsomething", data: "parameterhere=" +$(element).attr('attrHere'), type: 'GET', contentType: "application/json", dataType: "json", cache: false, success: function (result) { //do stuff }, error: function (xhr, ajaxOptions, thrownError) { //error handling } });
如果你做了ajax会像上面的代码一样发生什么?