使用jQuery mobile更改滑块的值/按下按钮时如何发布? [英] How to POST when slider's value is changed/button is pressed with jQuery mobile?

查看:87
本文介绍了使用jQuery mobile更改滑块的值/按下按钮时如何发布?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有1个滑块和1个按钮:

I have 1 slider and 1 button:

  <div data-role="fieldcontain">
    <input type="range" name="slider" id="slider" value="0" min="0" max="100"  />
  </div><br><br>
  <div data-role="fieldcontain">
    <select name="slider" id="slider" data-role="slider">
      <option value="off">Off</option>
      <option value="on">On</option>
    </select> 
  </div>

更改滑块的值后,如何发布(如form action="http://somesite" method="post")?按钮被按下了吗?

How can I POST (like form action="http://somesite" method="post"), when slider's value is changed? button is pressed?

推荐答案

$('#slider').change(function(){
    ...
    $.post(yoururl, yourdata, function(callbackdata){
        ...
    });
});

请参见 jQuery.post()顺便说一句:拥有2个具有相同ID的元素可能会导致重大问题迟早出现.

BTW: Having 2 elements with the same id will likely lead to major problems sooner than later.

如果您试图以这种方式从其他域获得响应,则除非他们为您提供JSONP之类的东西,否则您可能很不幸.由于同源策略限制,您将无法通过XMLHttpRequest从第三方网站获取内容.

Edit 2: If you're trying to get a response from a different domain this way, you're probably out of luck unless they offer you JSONP or the like. You will not be able to fetch content from a 3rd party site via XMLHttpRequest because of Same Origin Policy Limitations.

不过,您可以通过服务器代理请求,因此AJAX调用将转到同一个域.

You could proxy the request through your server, though, so the AJAX call would go to the same domain.

这篇关于使用jQuery mobile更改滑块的值/按下按钮时如何发布?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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