使用ajax传递#值无效

时间:2021-06-01 10:03:13

I am trying to get weinre working via Ajax by calling this on dom ready:

我试着通过Ajax让weinre工作通过调用dom:

$.ajax({
    url: 'http://debug.build.phonegap.com/target/target-script-min.js#hutber',
    dataType: "script",
    crossDomain: true,
    error: function(data){
        c(data.status);
    },
    success: function(data){
        c(data);
    }
});

Now, this is what is being sent:

现在,这是正在发送的:

 http://debug.build.phonegap.com/target/target-script-min.js?_=1381476442102

Which means that, for me to debug i have to use a randomly generated ID. I have tried this also: url: 'http://debug.build.phonegap.com/target/target-script-min.js?_=hutber', Just shooting in the dark.

这意味着,要调试,我必须使用随机生成的ID。在黑暗中射击。

So, am i write in thinking that the #hutber isn't being correctly sent with the request?

那么,我是否认为#hutber在发送请求时没有被正确地发送?

Edit

编辑

Just a quick thought, using $.ajax means that I am loading a script dynamically via a http request. As mentioned by Quentin you cannot pass #vars as these are client side. It occured to me however that I could pass the pass if I added the element into the body as if it were there on page load:

我只是想了一下,用$。ajax意味着我正在通过http请求动态加载脚本。正如昆汀提到的,你不能通过#vars,因为这些是客户端。但是我想到,如果我将元素添加到主体中,就好像它在页面加载中一样,我可以传递pass:

var s = document.createElement('script');
s.setAttribute("src","http://debug.build.phonegap.com/target/target-script-min.js#hutber");
document.getElementsByTagName('body')[0].appendChild(s);

Now, things should work out a little better, can't test this theory with a mobile phone however. But fingers crossed.

现在,事情应该会好一点,但不能用手机来测试这个理论。但祈祷。

1 个解决方案

#1


7  

Yes and No. You are right in thinking that #hutber not being sent with the request, but you are wrong in thinking that this is incorrect.

是的,没有。您认为#hutber没有被发送请求是正确的,但是您认为这是错误的。

The fragment identifier portion of a URL is handled purely client side so should never be sent to the server.

URL的片段标识符部分仅在客户端处理,因此不应该被发送到服务器。

If you want to attach data to a URL for the server to process, then use a query string (starting with a ? character and not a # character). If you have both a query string and a fragment identifier then the query string must come first.

如果要将数据附加到要处理的服务器的URL上,则使用查询字符串(以a开头)。字符,而不是#字符)。如果您同时拥有查询字符串和片段标识符,那么查询字符串必须首先出现。

jQuery will generate a query string for you if you include a data property to the object you pass to ajax (if you are using GET, as you are here).

如果您将一个数据属性包含到您传递给ajax的对象(如果您使用的是GET,就像您在这里一样),jQuery将为您生成一个查询字符串。

data { "_": "hutber" }

#1


7  

Yes and No. You are right in thinking that #hutber not being sent with the request, but you are wrong in thinking that this is incorrect.

是的,没有。您认为#hutber没有被发送请求是正确的,但是您认为这是错误的。

The fragment identifier portion of a URL is handled purely client side so should never be sent to the server.

URL的片段标识符部分仅在客户端处理,因此不应该被发送到服务器。

If you want to attach data to a URL for the server to process, then use a query string (starting with a ? character and not a # character). If you have both a query string and a fragment identifier then the query string must come first.

如果要将数据附加到要处理的服务器的URL上,则使用查询字符串(以a开头)。字符,而不是#字符)。如果您同时拥有查询字符串和片段标识符,那么查询字符串必须首先出现。

jQuery will generate a query string for you if you include a data property to the object you pass to ajax (if you are using GET, as you are here).

如果您将一个数据属性包含到您传递给ajax的对象(如果您使用的是GET,就像您在这里一样),jQuery将为您生成一个查询字符串。

data { "_": "hutber" }