2016-07-25 31 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