使用Jquery Ajax传参,当参数中带英文小括号时总是失败,大家有解决的方法吗?

由于参数比较多,使用jquery的serialize()方法收集参数

3个回答

失败是什么意思。。服务器报错自己检查服务器代码,serialize会用encodeURIComponent编码数据

showbo
支付宝加好友偷能量挖 回复flotang: post还是get?404肯定是你服务器配置有问题了,存在括号时导致url映射失败什么的
3 年多之前 回复
flotang
flotang 浏览器找不到地址,报404,去掉括号就可以,encodeURIComponent编码不会编码小括号
3 年多之前 回复

你们可以试一下,使用serialize参数如果有小括号会报404

你可以不纠结这个问题,可以在接受参数的一端,给传过去的参数加上括号(如果括号是必须的)

flotang
flotang 字符串,可能会带括号,不能确定,这个方法应用那么广泛,应该不会没有办法吧
3 年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
Python+OpenCV计算机视觉

Python+OpenCV计算机视觉

有关jq.ajax()使用json传参的问题

使用如下代码: $.ajax({ type: "Post", url: "Default.aspx/GetDir", data: "{'str':'E:\Users'}",//这样可以 contentType: "application/json; charset=utf-8", dataType: "json", success: function (data) { alert(eval('(' + data.d + ')')[1].lasttime); }, error: function () { alert("error!!!"); } }); 获取Users文件夹下文件的信息(这里是获取的访问时间),测试通过。 可是,我想用变量获取文件夹地址,放到json中传参,就测试失败了。代码如下: var folder2open="E:\Users"; //这里用变量获得Users的完整地址 $.ajax({ type: "Post", url: "Default.aspx/GetDir", data: "{'str':folder2open}", //注意这里的变化 contentType: "application/json; charset=utf-8", dataType: "json", success: function (data) { alert(eval('(' + data.d + ')')[1].lasttime); }, error: function () { alert("error!!!"); } }); 弹出对话框,提示“error!!!”。请问问题出在哪里?

jquery的表格插件 datatable使用ajax传递查询参数

jquery的表格插件 datatable使用ajax传递一写查询参数怎么写

jquery ajax请求 post 参数问题?

![图片说明](https://img-ask.csdn.net/upload/201702/11/1486777322_515993.png) 其中传递参数requestData 如果这个参数是requestData = {"login_name":"name"}:这样的写法 请求没有问题,php也能够获取到值 但是如果用jquery serializeArray 然后转换成json格式 则返回的是当前页面的html ,不是预先设定的值

如何通过 jQuery 传递 GET 请求中的参数?

<div class="post-text" itemprop="text"> <p>如何在jQueryAjax请求中传递查询字符串值?我目前这样做,但我相信有一个更干净的方式,不需要我手动编码。</p> <pre><code>$.ajax({ url: "ajax.aspx?ajaxid=4&amp;UserID=" + UserID + "&amp;EmailAddress=" + encodeURIComponent(EmailAddress), success: function(response) { //Do Something }, error: function(xhr) { //Do Something to handle error } }); </code></pre> <p>我曾经看到过查询字符串参数作为数组传递的例子,但是我看到的这些例子并没有使用$.ajax()模型,而是直接用了$. get ()。</p> <pre><code>$.get("ajax.aspx", { UserID: UserID , EmailAddress: EmailAddress } ); </code></pre> <p>我更喜欢使用$.ajax()格式,因为它是我习惯的(没有特别好的理由--只是个人偏好)。</p> <p><strong>更新于 09/04/2013:</strong></p> <p>在我的问题解决后(因为“过于本地化”),我发现了一个类似的问题:</p> <p><a href="https://stackoverflow.com/questions/3066070/using-jquery-to-make-a-post-how-to-properly-supply-data-parameter">如何使用jQuery来发布文章,如何正确地提供“数据”参数?</a></p> <p>这完美地回答了我的问题,我发现这样做更容易阅读,而且我不需要在URL或数据值中手动使用 encodeURIComponent() (这是我在BIPEN的答案中发现的不理解的内容)。 <p>这是因为 data 数值被$.param()自动编码了。 <p>为了防止这对其他人有用,下面就是我的例子:</p> <pre><code>$.ajax({ url: "ajax.aspx?ajaxid=4", data: { "VarA": VarA, "VarB": VarB, "VarC": VarC }, cache: false, type: "POST", success: function(response) { }, error: function(xhr) { } }); </code></pre> </div>

如何使用 jQuery 传递 GET 请求中的参数

<div class="post-text" itemprop="text"> <p>How should I be passing query string values in a jQuery Ajax request? I currently do them as follows but I'm sure there is a cleaner way that does not require me to encode manually.</p> <pre><code>$.ajax({ url: "ajax.aspx?ajaxid=4&amp;UserID=" + UserID + "&amp;EmailAddress=" + encodeURIComponent(EmailAddress), success: function(response) { //Do Something }, error: function(xhr) { //Do Something to handle error } }); </code></pre> <p>I’ve seen examples where query string parameters are passed as an array but these examples I've seen don't use the <code>$.ajax()</code> model, instead they go straight to <code>$.get()</code>. For example:</p> <pre><code>$.get("ajax.aspx", { UserID: UserID , EmailAddress: EmailAddress } ); </code></pre> <p>I prefer to use the $.ajax() format as it's what I’m used to (no particularly good reason - just a personal preference).</p> <p><strong>Edit 09/04/2013:</strong></p> <p>After my question was closed (as "Too Localised") i found a related (identical) question - with 3 upvotes no-less (My bad for not finding it in the first place):</p> <p><a href="https://stackoverflow.com/questions/3066070/using-jquery-to-make-a-post-how-to-properly-supply-data-parameter">Using jquery to make a POST, how to properly supply 'data' parameter?</a></p> <p>This answered my question perfectly, I found that doing it this way is much easier to read &amp; I don't need to manually use <code>encodeURIComponent()</code> in the URL or the DATA values (which is what i found unclear in bipen's answer). This is because the <code>data</code> value is encoded automatically via <a href="http://api.jquery.com/jQuery.param/" rel="noreferrer"><code>$.param()</code></a>). Just in case this can be of use to anyone else, this is the example I went with:</p> <pre><code>$.ajax({ url: "ajax.aspx?ajaxid=4", data: { "VarA": VarA, "VarB": VarB, "VarC": VarC }, cache: false, type: "POST", success: function(response) { }, error: function(xhr) { } }); </code></pre> </div> <p>转载于:https://stackoverflow.com/questions/15576548/how-to-pass-parameters-in-get-requests-with-jquery</p>

JQuery的Post传参数为什么收不到呢?

[code=JScript]$.post("sealmaker.DrawArea", { action:redraw, shape:shape, color:sealcolor, text:text, style:textstyle, size:textsize} function(result) { alert(result); } ); [/code] 我是想把上面的几个参数传递到DrawArea类中的redraw方法中,但始终传不成功呢?

在 jQuery AJAX GET 调用中传递请求头

<div class="post-text" itemprop="text"> <p>I am trying to pass request headers in an AJAX GET using jQuery. In the following block, "data" automatically passes the values in the querystring. Is there a way to pass that data in the request header instead ?</p> <pre><code>$.ajax({ url: "http://localhost/PlatformPortal/Buyers/Account/SignIn", data: { signature: authHeader }, type: "GET", success: function() { alert('Success!' + authHeader); } }); </code></pre> <p>The following didn't work either </p> <pre><code>$.ajax({ url: "http://localhost/PlatformPortal/Buyers/Account/SignIn", beforeSend: { signature: authHeader }, async: false, type: "GET", success: function() { alert('Success!' + authHeader); } }); </code></pre> </div> <p>转载于:https://stackoverflow.com/questions/3258645/pass-request-headers-in-a-jquery-ajax-get-call</p>

如何在jquery中传递php参数

<div class="post-text" itemprop="text"> <p>From Here I am doing like I fetch data from database and display in table format still it is working fine, after I click the <code>division_edit()</code> function I want pass the value (<code>id</code>),how can do this.</p> <p></p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false"> <div class="snippet-code"> <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;table id="dataTable" class="table table-bordered table-hover"&gt; &lt;thead&gt; &lt;tr&gt; &lt;th&gt;S.No&lt;/th&gt; &lt;th&gt;Division&lt;/th&gt; &lt;th&gt;Action&lt;/th&gt; &lt;/tr&gt; &lt;/thead&gt; &lt;tbody&gt; &lt;?php $sql=m ysql_query( "SELECT * FROM division WHERE status !='1'"); for($i=1;$row=m ysql_fetch_assoc($sql);$i++){ ?&gt; &lt;tr role="row" class="odd"&gt; &lt;td&gt; &lt;?php echo $i;?&gt; &lt;/td&gt; &lt;td&gt; &lt;?php echo $row[ 'division'];?&gt; &lt;/td&gt; &lt;td&gt;&lt;a class="btn btn-success btn-xs" href="state_edit.php?id=&lt;?php echo base64_encode($row['id']);?&gt;" onclick="division_edit()" id="division_edit"&gt;&lt;i class="fa fa-pencil-square-o"&gt;&lt;/i&gt; Edit&lt;/a&gt; &lt;button class="btn btn-danger btn-xs" data-href="state_delete.php?id=&lt;?php echo base64_encode($row['id']);?&gt;" data-toggle="modal" data-target="#confirm-delete"&gt;&lt;i class="fa fa-trash"&gt;&lt;/i&gt; Delete&lt;/button&gt; &lt;/td&gt; &lt;/tr&gt; &lt;?php } ?&gt; &lt;/tbody&gt; &lt;tfoot&gt; &lt;tr&gt; &lt;th&gt;S.No&lt;/th&gt; &lt;th&gt;Division&lt;/th&gt; &lt;th&gt;Action&lt;/th&gt; &lt;/tr&gt; &lt;/tfoot&gt; &lt;/table&gt;</code></pre> </div> </div> </div>

使用jquery ajax解决302重定向问题

<div class="post-text" itemprop="text"> <p>Due to some requirement I need to login to a site using jquery ajax .. but when I try to do so .. the firebug console is saying that it is 302 error. I have tried to implement the code for its handling but unfortunately with no success</p> <p>Here is my code I have tried till now : </p> <pre><code>&lt;script type='text/javascript' src='http://code.jquery.com/jquery.js'&gt; &lt;/script&gt; &lt;script type='text/javascript'&gt; $(document).ready(function(){ $.ajax({ url : "https://testDomain/login.asp", async : false, type : 'POST', data : {Username:'test',Password:'testPass'}, success : function(respText){alert(respText);}, error : function (jqXHR, textStatus, errorThrown) { console.log(jqXHR.getResponseHeader("Location")); // undefined; }, statusCode: { 302: function() { alert("page not found"); } }, complete : function(response) { if(response.status == 302) { window.alert('page not found'); } } }) }); &lt;/script&gt; </code></pre> <p>when I see the response headers they show up as </p> <pre><code>Date Wed, 13 Mar 2013 06:43:18 GMT Location https://testDomain/pageXXX.asp Server Microsoft-IIS/6.0 Set-Cookie TravAuthV=e;path=/; domain=testDomain.com; X-Powered-By ASP.NET </code></pre> <p>What am I missing .. ?? Or is there any other alternative to handle this</p> <p>Thanks for your time .. any help will be appreciated... </p> </div>

jquery ajax的文档里没有headers参数,为什么可以直接在settings里面放headers参数?

![图片说明](https://img-ask.csdn.net/upload/201810/30/1540901789_934226.jpg) jquery ajax的文档里没有headers参数,为什么可以直接在settings里面放headers参数? 有人会把token放在header里面上传。

jquery ajax没响应

各位,使用jquery ajax post发送请求,请求参数(data)太长则后台接收不到请求。 如果将data改为“1234”等简单的参数,则发送成功。因此可以确定是参数的问题。 [code="html"] $.ajax({ method:"POST", url: ajaxRequestURL, //data: "1234", data: requestParams, async: true, cache: false, dataType: "text" }); [/code] requestParams的格式为: [code="html"] var params=""; for(var i=0;i<phoneNumbers.length;i++){ params+="insertMemberDto.orders["+i+"].memberPhone="+tds[(i*7+0)]+"&"+ "insertMemberDto.orders["+i+"].memberName="+tds[(i*7+1)]+"&"+ "insertMemberDto.orders["+i+"].memberEmail="+tds[(i*7+2)]+"&"+ "insertMemberDto.orders["+i+"].memberPassword="+tds[(i*7+3)]+"&"+ "insertMemberDto.orders["+i+"].memberNumber="+tds[(i*7+4)]+"&"+ "insertMemberDto.orders["+i+"].memberUsualNumber="+tds[(i*7+5)]+"&"+ "insertMemberDto.orders["+i+"].memberProductId="+tds[(i*7+6)]+"&"; } requestParams=params.slice(0,params.length-1); [/code] 发送请求前alert出url和data,确定没有问题,直接在地址栏敲入url也没有问题,所以确定是请求参数data的问题。比较长,最大可达到1000个字符,按理说使用post发送也没什么问题...是字符格式吗?在firefox 看请求内容,各项参数也都正确,WHY? 请求达人相助!

如何实现ASP.NET中使用jQuery中的ajax与后台的交互,求指点

怎样才能使用jquery中ajax与后台的交互,做毕业设计,想要用普通的html标签,再通过ajax能实现与后台的交互

如何将输入文本框值的参数传递给jQuery中的ajax

<div class="post-text" itemprop="text"> <p>My Ajax code </p> <pre><code>$(document).ready(function() { $("#sub").click(function() { $.ajax({ type: "POST", url: "jqueryphp.php", data: "txt1=" + txt1, success: function(result) { $("div").html(result); } }); }); });​ </code></pre> <p>This is the form code . I want to pass txt1 value to Ajax</p> <pre><code>&lt;input type="text" name="txt1" id="txt1" /&gt;&lt;br&gt; &lt;input type="button" name="sub" id="sub" value="click Me" /&gt; </code></pre> <p>I want to pass <strong>txt1</strong> value to my php page using this Ajax function. </p> <p>Please tell me what exactly will come in the data attribute of Ajax</p> </div>

POST Jquery AJAX错误500

<div class="post-text" itemprop="text"> <p>I have a strange problem. Yesterday everything worked fine.</p> <p>I have a simple php file, as follows:</p> <pre><code>&lt;?php if ($_SERVER['REQUEST_METHOD'] === 'POST') { echo json_encode(['messageType' =&gt; 'success','message'=&gt;$_POST['key']); die(); } </code></pre> <p>And js file with Ajax query:</p> <pre><code>$.ajax({ dataType: "json", type: "POST", url: 'get.php', data: {key: 'a'}, success: function(data) { alert(data.message) }, error: function(data) { alert ('error');} }); </code></pre> <p>When the field 'key' is set to 1 character (eg. 'a'), I get an error 500 from the server. But if I change it to at least 3 characters everything works just fine.</p> <p>The problem's begun occurring suddenly on several independent servers.</p> </div>

ajax 传递参数要打引号吗?

$.post({ url:"/user/check", data:{ username:username } }); 1.url前面要加basepath吗? 2.前面的那个username要加双引号吗? 3.后台是直接把username写到方法参数中获取吗?

如何在jquery中传递参数

<div class="post-text" itemprop="text"> <p>I am supposed to submit 2 values called str and name to another page.But only 1value is getting returned in the next page. When I include name and on next page if I say <code>print_r($_POST)</code>,then even the first value is not getting printed. I have written a function as follows,which works because there is only one parameter.</p> <pre><code>function sendValue(str) { $.post( "newsletter/subscribe.php", //Ajax file { sendValue: str }, function(data){ $('#display').html(data.returnValue); }, "json" ); } </code></pre> <p>But if I pass 2 values in that function and in <code>$.post</code>, I do <code>sendValue:str,name</code> then I am not getting even 1 value.</p> </div>

在刀片视图中从jquery变量传递路由参数

<div class="post-text" itemprop="text"> <p>How to add the <code>delete_id = $(this).attr('delete_id');</code> jquery variable in the <code>'product_id' =&gt; ????</code> of the ajax <code>url</code></p> <p>I have this route: <code>Route::delete('/{store}/{table_name}_{table_id}/{receipt_id}/shop/cart/{product_id}', 'Cart\CartController@destroy')-&gt;name('cart.destroy');</code></p> <p>and this ajax:</p> <pre><code> $(document).on('submit','#cartItem_delete',function(e){ delete_id = $(this).attr('delete_id'); var form_data = $(this).serialize(); //prepare form data for Ajax post $.ajax({ type: "DELETE", url: '{{ route('cart.destroy', ['product_id' =&gt; ????, 'store' =&gt; $store, 'table_name' =&gt; $table_name, 'table_id' =&gt; $table_id, 'receipt_id' =&gt; $receipt_id]) }}', dataType:"json", //expect json value from server data: form_data }).done(function(data){ //on Ajax success $('tr[row='+delete_id+']').remove(); $('.cart-button a span').text(data.count); if (data.count &lt; 1) { $('.container #cartContainer').remove(); location.reload(); } }); e.preventDefault(); }); </code></pre> <p>The html form is in a <code>foreach</code> statement (for each row in the cart) and the row id is in the <code>delete_id</code> attribute:</p> <pre><code>&lt;form id="cartItem_delete" delete_id="{{ $item-&gt;rowId }}" class="side-by-side"&gt; {!! csrf_field() !!} &lt;input type="hidden" name="_method" value="DELETE"&gt; &lt;button type="submit" class="btn btn-danger btn-sm" value="Remove"&gt;Remove&lt;/button&gt; &lt;/form&gt; </code></pre> </div>

等待所有 jQuery Ajax 请求完成?

<div class="post-text" itemprop="text"> <p>How do I make a function wait until all jQuery Ajax requests are done inside another function?</p> <p>In short, I need to wait for all Ajax requests to be done before I execute the next. But how?</p> </div> <p>转载于:https://stackoverflow.com/questions/3709597/wait-until-all-jquery-ajax-requests-are-done</p>

PHP HTML输入将多个参数传递给jQuery AJAX调用

<div class="post-text" itemprop="text"> <p>I'm working on my first HTML form that performs an AJAX HTTP POST using jQuery. When a user makes a change to an input text field and tabs out of the field I want it to trigger the AJAX call and pass the value of the input field as well as the value from another PHP variable.</p> <p>Here's the input in question:</p> <pre><code>&lt;td&gt;&lt;input type="text" class="form-control" id="storeManager" name="storeManager" value="Peter McMahon"&gt;&lt;/td&gt; </code></pre> <p>I have a PHP variable - $uuid - which I also need to pass to my AJAX script, as well as the value of the input text field.</p> <p>Here's my script as it currently stands:</p> <pre><code>&lt;script type="text/javascript"&gt; $(document).ready(function() { $("#storeManager").change(function(){ $.ajax({ url: "editProject.php", data: { storeManager: storeManager, uuid: uuid }, success: function(data) { $("#storeManager").html(data).addClass("has-success"); }, error: function (data) { $("#storeManager").html(data).addClass("has-error"); } }); }); }); &lt;/script&gt; </code></pre> <p>I'm new to jQuery and AJAX and have tried everything I can think of but not sure how to add the required parameters?</p> </div>

2019 Python开发者日-培训

2019 Python开发者日-培训

150讲轻松搞定Python网络爬虫

150讲轻松搞定Python网络爬虫

设计模式(JAVA语言实现)--20种设计模式附带源码

设计模式(JAVA语言实现)--20种设计模式附带源码

YOLOv3目标检测实战:训练自己的数据集

YOLOv3目标检测实战:训练自己的数据集

java后台+微信小程序 实现完整的点餐系统

java后台+微信小程序 实现完整的点餐系统

三个项目玩转深度学习(附1G源码)

三个项目玩转深度学习(附1G源码)

初级玩转Linux+Ubuntu(嵌入式开发基础课程)

初级玩转Linux+Ubuntu(嵌入式开发基础课程)

2019 AI开发者大会

2019 AI开发者大会

玩转Linux:常用命令实例指南

玩转Linux:常用命令实例指南

一学即懂的计算机视觉(第一季)

一学即懂的计算机视觉(第一季)

4小时玩转微信小程序——基础入门与微信支付实战

4小时玩转微信小程序——基础入门与微信支付实战

Git 实用技巧

Git 实用技巧

Python数据清洗实战入门

Python数据清洗实战入门

使用TensorFlow+keras快速构建图像分类模型

使用TensorFlow+keras快速构建图像分类模型

实用主义学Python(小白也容易上手的Python实用案例)

实用主义学Python(小白也容易上手的Python实用案例)

程序员的算法通关课:知己知彼(第一季)

程序员的算法通关课:知己知彼(第一季)

MySQL数据库从入门到实战应用

MySQL数据库从入门到实战应用

机器学习初学者必会的案例精讲

机器学习初学者必会的案例精讲

手把手实现Java图书管理系统(附源码)

手把手实现Java图书管理系统(附源码)

极简JAVA学习营第四期(报名以后加助教微信:eduxy-1)

极简JAVA学习营第四期(报名以后加助教微信:eduxy-1)

.net core快速开发框架

.net core快速开发框架

玩转Python-Python3基础入门

玩转Python-Python3基础入门

Python数据挖掘简易入门

Python数据挖掘简易入门

微信公众平台开发入门

微信公众平台开发入门

程序员的兼职技能课

程序员的兼职技能课

Windows版YOLOv4目标检测实战:训练自己的数据集

Windows版YOLOv4目标检测实战:训练自己的数据集

HoloLens2开发入门教程

HoloLens2开发入门教程

微信小程序开发实战

微信小程序开发实战

Java8零基础入门视频教程

Java8零基础入门视频教程

相关热词 c# cad插入影像 c#设计思想 c#正则表达式 转换 c#form复制 c#写web c# 柱形图 c# wcf 服务库 c#应用程序管理器 c#数组如何赋值给数组 c#序列化应用目的博客园
立即提问