简体   繁体   English

为什么ajax调用不能在相同的URL下正常工作?

[英]Why the ajax call is not working properly with same url?

There are two ajax calls with same url not working properly? 有两个具有相同网址的Ajax调用无法正常工作?

var ss=35;
function t()
{
$.ajax({type:"POST",
          url:"BillServlet",
          data1:{message1:ss},                                                                 
          success:function(data1){
          alert('success'+data1.message1)
          }});} //this function returns null

function test()
{
$.ajax({type:"POST",
          url:"BillServlet",
          data:{message:total},                                                                 
          success:function(data){
          alert('success'+data.message)
          }});}//this function returns value

Why one function returns null value? 为什么一个函数返回空值?

Assuming you're trying to get the same data back from the server in both functions, in function t() you should change data1.message1 to data1.message . 假设您试图通过两个函数从服务器获取相同的数据,则在function t() ,应将data1.message1更改为data1.message

Otherwise, try printing out the value of data1 to see what data the server is actually giving you. 否则,请尝试打印出data1的值以查看服务器实际为您提供的数据。 If you can't use console.log(data1) for some reason, you could also use alert(JSON.stringify(data1)) 如果由于某种原因无法使用console.log(data1) ,则也可以使用alert(JSON.stringify(data1))

Check in the firbug, are you getting the response from server? 检入firbug,您是否从服务器获得响应? I think you are getting the blank response from server. 我认为您正在从服务器得到空白响应。 If you are getting the response then check the indexes in the response that is it same you are alerting. 如果您得到响应,请检查响应中与您警报相同的索引。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM