2016-07-25 75 views
1

在我的jQuery POST请求的URL被定向到本地主机总是(有消息http://127.0.0.1:8080/MyApp/[object Object]jQuery的POST重定向到http://127.0.0.1:8080/MyApp/[object对象]

有了一个jQuery GET工作正常(连接到外部URL)。

如何更改POST行为以访问指定的URL?

var tmpurl='https://myhost.com/message'; 
$.post({ 
    data: { 
    'v': value, 
    'key' : 'MyKey' 
    }, 
    dataType: 'jsonp', 
    url: tmpurl, 
    success: function(response) { 
    console.log("success!", response); 
} 
}); 
+0

你是什么意思重定向?并尝试使用json作为dataType而不是jsonp –

+0

我的意思是它不使用目标url(https://myhost.com/message)作为目标,但尝试连接到本地主机。 jsonp用于跨域请求。用json dataType尝试,但不起作用。 – RajCherla

回答

0

既然你正在通过HTTPS Ajax调用,我会建议你在像/message/末有一个额外的/。对于跨域请求使用crossDomain: true.

var tmpurl='https://myhost.com/message/'; 
$.post({ 
    data: { 
    'v': value, 
    'key' : 'MyKey' 
    }, 
    crossDomain: true, 
    dataType: 'json', 
    url: tmpurl, 
    success: function(response) { 
    console.log("success!", response); 
} 
}); 

这应该解决您的问题。

+0

以上尝试但仍然不工作Shubham。 – RajCherla

+0

@RajCherla你确定服务器不会导致重定向吗 –

+0

不,它不是服务器重定向。看起来像POST将url设置为默认值。 – RajCherla