【发布时间】:2014-03-27 22:22:57
【问题描述】:
每当拖动或改变谷歌地图的缩放比例时,都会调用callAjax函数。
当我想发送消息时,ajax 请求被执行:
multiline in var url http://screencloud.net/img/screenshots/9be42375b3978da687b944a376861c82.png
null 和 http://localhost:8888/ptf/public/products/1/iWant => 是同一个变量 (urlIWant)
行数等于我们拖动或改变谷歌地图缩放的次数,这个例子是改变3次(2 null + localhost)
我们每次更改谷歌地图callAjax都会执行:
function callAjax(page){
// instancie la variable
var urlIWant = null;
/* Google maps */
var bds = map.getBounds();
var South_Lat = bds.getSouthWest().lat();
var South_Lng = bds.getSouthWest().lng();
var North_Lat = bds.getNorthEast().lat();
var North_Lng = bds.getNorthEast().lng();
dataQuery = 'SO_Lt='+South_Lat+'&SO_lg='+South_Lng+'&NE_lt='+North_Lat+'&NE_lg='+North_Lng+'&showUser='+showUser;
// Ajax request who return me the html who contain the products
$.ajax({
type: "GET",
url: 'search',
data: dataQuery,
beforeSend: function() {
$('#loader').removeClass('hidden');
$('#result').addClass('hidden');
},
success: handleResponse
});
当用户点击模态“我想要”时
$('.iWant').click(function(event) {
// Stop the loading
event.preventDefault();
// catch the url for Ajax Request
urlIWant = $(this).attr('href');
$('#iWantModal').modal('show');
});
当用户点击发送消息时
$('#sendMessage').click(function(){
// show the multiple line
console.log(urlIWant);
// call ajax (API)
$.ajax({
url: urlIWant,
method: "POST",
data: {
messageSend: $('#messageSend').val(),
emailSend: $('#emailSend').val(),
name: $('#userName').text(),
userId: $('#userId').text()
},
beforeSend: function(request) {
return request.setRequestHeader('X-CSRF-Token', $("input[name='_token']").val());
},
success: function() {
// Close the modal
$('#iWantModal').modal('hide');
$("#messageSend").val('');
},
// When ajax request is complete (success or error)
complete : function(){
urlIWant = null;
}
});
});
}
}
如何保持结束行http://localhost:8888/ptf/public/products/1/iWant?
以及为什么每次 callAjax 都被称为 incremente 'urlIWant' 而不是 replace
谢谢
【问题讨论】:
-
请清理您的问题并删除任何不相关的代码。现在,无法说出你在问什么。
-
对不起,现在可以了吗?
-
否;我们仍然不知道你在问什么。这是什么意思:“如何保持结束行localhost:8888/ptf/public/products/1/iWant?”这是什么意思:“为什么每次 callAjax 都被称为增量 'urlIWant' 而不是替换?”您不会在任何地方增加
urlIWant。 -
我不明白为什么
urlIWant包含多行。然而urlIWant = $(this).attr('href');必须为新内容增加旧内容。在这里,它添加了一行。你明白吗(对不起我的英语)? -
对不起,我不明白。您需要解释(并举例说明)“
urlIWant包含多行”的含义(“多行”在英语中没有真正的含义)。您需要解释并举例说明“但urlIWant = $(this).attr('href');必须为新内容增加旧内容”。 “必须为新内容增加旧内容”是什么意思?
标签: javascript jquery var