重定向到从json响应中获取的url [英] redirect to url taken from json response

查看:174
本文介绍了重定向到从json响应中获取的url的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用jquery ajax方法向php网页发出http请求,作为回应我正在使用json像{status:success,url:http url}

I am using jquery ajax method to make http request to php webpage, and in response I am taking json like {"status":"success","url":"http url"}

成功函数我从json重定向到url,但大部分时间都失败了。我使用以下来重定向:

on success function I am redirecting to url from json but most of the time it fails. I am using following to redirect:

window.location.href = url

当url干净而没有其他字符时它工作正常,但是当我有#或空格或其他字符时失败。请知道是否有办法解决我的问题。

It works fine when url is clean with no other characters, but fails when I have # or space or some other characters. Please letme know if there is any way to solve my problem.

推荐答案

我个人使用

    window.location.replace(url);

阅读更多 - replace()方法用新的替换当前文档
window.location.replace()更好地模拟http重定向

Read More - "The replace() method replaces the current document with a new one" window.location.replace() better simulates a http redirect

还有其他各种选项,例如:

There are other various options like:

window.location.href = "http://stackoverflow.com";

用作链接点击

这篇关于重定向到从json响应中获取的url的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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