0

我正在尝试将网站加载到 div ( div.content) 中。

该网站需要通过 POST 登录。

javascript 尝试加载站点,检测到登录表单的重定向,发布用户名和密码,最后重新加载 url,因为身份验证成功。

现在的问题是 url 构造不正确。网址应该是这样的:

https://mysite.com/WebUntis/index.do?school=schoolname#Timetable?
onlyTimetable=true&ajaxCommand=renderTimetable&date=20130418&type=1&id=17
&formatId=2&departmentId=-1&buildingId=-1

但是 jquery 像这样构建它:

https://mysite.com/WebUntis/index.do?
onlyTimetable=true&ajaxCommand=renderTimetable&date=20130418&type=1&id=17
&formatId=2&departmentId=-1&buildingId=-1.

有人可以帮我吗?我通过查看大量示例检查了语法,但找不到修复程序。

function openUrl()
{
  jQuery.ajax({
   url: 'https://mysite.com/WebUntis/index.do?school=schoolname#Timetable?',
   type:'GET',
   dataType: 'html',
   data: {
      //school: 'schoolname',
      ajaxCommand: 'renderTimetable',
      onlyTimetable: 'true',
      date: '20130418',
      type: '1',
      id: '17',
      formatId: '2',
      departmentId: '-1',
      buildingId: '-1'
   },
   success: function(result) {
      var html = jQuery('<div>').html(result);
      if(html.find("form").attr("id") == "login")//login form found
      {
          alert("Trying to login...");
          login(); //This just POSTs a username and password
      };
      $('div.content').html(result);
    },
  });
} 
4

1 回答 1

0

尝试编码参数school

function openUrl()
{
    jQuery.ajax({
        url: 'https://mysite.com/WebUntis/index.do',
        type:'GET',
        dataType: 'html',
        data: {
            school: encodeURIComponent('schoolname#Timetable?'),
            ajaxCommand: 'renderTimetable',
            onlyTimetable: 'true',
            date: '20130418',
            type: '1',
            id: '17',
            formatId: '2',
            departmentId: '-1',
            buildingId: '-1'
        },
        success: function(result) {
            var html = jQuery('<div>').html(result);
            if(html.find("form").attr("id") == "login")//login form found
            {
                alert("Trying to login...");
                login(); //This just POSTs a username and password
            };
            $('div.content').html(result);
        },
    });
} 
于 2013-04-27T13:25:16.723 回答