我想在我的word press项目中使用带有GET方法的ajax提交表单。
我尝试了两种方法,但这对我不起作用,我的代码中有任何问题。
方法-1使用$ .get
$.get( "http://**.70.120.**/web/sms.aspx", { fullname: "John", contactnumber: "123333",Email_ID:"aniruddha@thinkbar.in",State:"MP",City:"Indore",Magma_Customer:"YES",Proposal_Number:"1234567890",Service_type:"CASE",Query_Type:"Test type",Message:"Hellotesting" } )
.done(function( data ) {
alert( "Data Loaded: " + data );
})
.fail(function( data ) {
alert( "Data NOT Loaded: " + data );
});
方法-2使用Ajax
$.ajax({
method: "GET",
url: "http://**.70.120.**/webleads/sms.aspx",
data: {fullname: "John", contactnumber: "123333",Email_ID:"aniruddha@thinkbar.in",State:"MP",City:"Indore",Magma_Customer:"YES",Proposal_Number:"1234567890",Service_type:"CASE",Query_Type:"Test type",Message:"Hellotesting" }
})
.done(function( msg ) {
alert( "Data Saved: " + msg );
})
.fail(function( msg ) {
alert( "Data NOT Saved: " + msg );
})
请帮忙
答案 0 :(得分:1)
如果你想使用ajax
$.ajax({
data: { fullname: "John", contactnumber: "123333",Email_ID:"aniruddha@thinkbar.in",State:"MP",City:"Indore",Magma_Customer:"YES",Proposal_Number:"1234567890",Service_type:"CASE",Query_Type:"Test type",Message:"Hellotesting" },
url: "http://**.70.120.**/web/sms.aspx",
type: "GET",
success: function(msg){
//some function here
}
});
答案 1 :(得分:1)
你可以这样做
$.ajax({
type: 'GET',
url: 'http://**.70.120.**/webleads/sms.aspx',
data: {
'fullname': 'John',
'contactnumber': '123333',
'Email_ID': 'aniruddha@thinkbar.in',
'State': 'MP',
'City': 'Indore',
'Magma_Customer': 'YES',
'Proposal_Number': '1234567890',
'Service_type': 'CASE',
'Query_Type': 'Test type',
'Message': 'Hellotesting'
},
dataType: 'application/x-www-form-urlencoded',
success: function(response) {
console.log( response );
},
error: function(errorThrown) {
console.log( errorThrown );
},
});
将在您的服务器上提交的网址为http://**.70.120.**/webleads/sms.aspx/?fullname=John&contactnumber=123333&Email_ID=aniruddha@thinkbar.in&State=MP&City=Indore&Magma_Customer=YES&Proposal_Number=1234567890&Service_type=CASE&Query_Type=Test%20type&Message=Hellotesting