全局变量未在ajax调用中显示结果 [英] Global variable is not showing result inside a ajax call

查看:62
本文介绍了全局变量未在ajax调用中显示结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好

这里的index是一个全局变量.我正在另一个函数中操作索引.

之后,我调用此函数.它在ajax调用之后和之后显示实际结果,但在ajax调用内部未显示.

Hi all

Here index is a global variable. I am manipulating the index in another function.

After that I call this function. its showing the actual result outside and after the ajax call but not showing inside the ajax call.

var urlSearch = "http://192.168.10.113/collective-intellegence/UserClickPersonClassifier?userid=1&query=asp.net";
alert(index);
$.ajax({
    url: urlSearch,
    type: 'POST',
    dataType: 'json',
    success: function (data) {
        alert(index);
    }
});


我有做错什么吗?

请帮助解决此问题.

在此先感谢您.


Is there any mistake done by me.

Please help to solve this problem.

Thanks in advance.

推荐答案

.ajax({ url:urlSearch, 类型:' POST', dataType:' json', 成功:功能(数据){ 警报(索引); } });
.ajax({ url: urlSearch, type: 'POST', dataType: 'json', success: function (data) { alert(index); } });


我有做错什么吗?

请帮助解决此问题.

预先感谢.


Is there any mistake done by me.

Please help to solve this problem.

Thanks in advance.


如果看不到全局变量,则可以创建本地副本,如var i = index;.并在您的AJAX回调中访问i.如果这不是一个奇怪的范围问题,那么您未向我们展示的代码就有问题.
If it can''t see a global, you could create a local copy as in, var i = index; and access i inside your AJAX callback. If it''s not a weird scoping issue, then there''s an issue with the code you''ve not shown us.


这篇关于全局变量未在ajax调用中显示结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆