jQuery는 POST 매개 변수로 문자열을 보냅니다.
문자열을 ajax Post 매개 변수로 보내고 싶습니다.
다음 코드 :
$.ajax({
type: "POST",
url: "http://nakolesah.ru/",
data: 'foo=bar&ca$libri=no$libri',
success: function(msg){
alert('wow'+msg);
}
});
작동하지 않는다. 왜?
다음과 같이 시도하십시오.
$.ajax({
type: 'POST',
// make sure you respect the same origin policy with this url:
// http://en.wikipedia.org/wiki/Same_origin_policy
url: 'http://nakolesah.ru/',
data: {
'foo': 'bar',
'ca$libri': 'no$libri' // <-- the $ sign in the parameter name seems unusual, I would avoid it
},
success: function(msg){
alert('wow' + msg);
}
});
$.ajax({
type: 'POST',
url:'http://nakolesah.ru/',
data:'foo='+ bar+'&calibri='+ nolibri,
success: function(msg){
alert('wow' + msg);
}
});
그들이 당신의 질문을 이해하지 못했다는 것을 압니다. 대답은 다음과 같이 ajax 호출에 "전통적인"매개 변수를 추가하는 것입니다.
$.ajax({
traditional: true,
type: "POST",
url: url,
data: custom ,
success: ok,
dataType: "json"
});
그리고 문자열로 전달 된 매개 변수와 함께 작동합니다.
비슷한 응용 프로그램의 경우 다음 data
과 JSON.stringify()
같이 개체 를 래핑해야 했습니다.
data: JSON.stringify({
'foo': 'bar',
'ca$libri': 'no$libri'
}),
API는 REST 클라이언트와 함께 작동했지만 브라우저에서 jquery ajax와 함께 작동하지 못했습니다. stringify가 해결책이었습니다.
이것이 여전히 실제인지 확실하지 않습니다. 미래의 독자를위한 것입니다. 정말로 원하는 것이 URL의 일부로 매개 변수를 전달하는 것이라면 아마도 jQuery.param ()을 사용해야 합니다.
Not a direct answer to your question.. But following is the only syntax that used to work for me -
data: '{"winNumber": "' + win + '"}',
And the parameter-name match with the argument of the server method
I was facing the problem in passing string value to string parameters in Ajax. After so much googling, i have come up with a custom solution as below.
var bar = 'xyz';
var calibri = 'no$libri';
$.ajax({
type: "POST",
dataType: "json",
contentType: "application/json; charset=utf-8",
url: "http://nakolesah.ru/",
data: '{ foo: \'' + bar + '\', zoo: \'' + calibri + '\'}',
success: function(msg){
alert('wow'+msg);
},
});
Here, bar and calibri are two string variables and you can pass whatever string value to respective string parameters in web method.
I have also faced this exact problem. But I have got a solution and it worked perfectly. I have needed to pass the parameters which are already produced by javascript function. So below code is working for me. I used ColdFusion for the backend. I just directly used the parameters as a variable.
$.ajax({
url: "https://myexampleurl.com/myactionfile.cfm",
type: "POST",
data : {paramert1: variable1,parameter2: variable2},
success: function(data){
console.log(data);
} )};
참고URL : https://stackoverflow.com/questions/5046930/jquery-send-string-as-post-parameters
'IT story' 카테고리의 다른 글
c # : 게터 / 세터 (0) | 2020.09.06 |
---|---|
GUI를 통해 TFS에서 다른 사용자의 체크 아웃을 실행 취소하는 방법은 무엇입니까? (0) | 2020.09.06 |
C로 현재 시간 가져 오기 (0) | 2020.09.06 |
CoffeeScript 정의되지 않음 (0) | 2020.09.06 |
모든 Rails 도우미를 모든 뷰에서 항상 사용할 수있는 이유는 무엇입니까? (0) | 2020.09.06 |