为什么ajax不起作用 [英] why ajax dose n't work
本文介绍了为什么ajax不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
为什么$ .ajax无效。并显示错误。
< script type = text / javascript>
{
$( document )。ready( function ( ){
alert(' hi');
$(' #CountryAndCity')。change( function () {
var str = document .getElementById(' CountryAndCity')。value;
var str1 = str.split( ,, 1 )。toString();
var str2 = str.split( ,, 2 )。toString();
$ .ajax({
url:' / AccountController / Myaction',
data:{countryy:str1,cityy:str2},
cache: false ,
输入:' GET',
成功:函数(结果){
$(' hidMyModelid_city' ).val(结果);
},
错误: function (xhr,ajaxOptions ,thrownError){
alert(thrownErr要么);
},
});
})
});
}
< / script
public ActionResult MyAction( string countryy, string cityy)
{
var result = MyClass.GetIDCity(countryy,cityy);
return Json(result,JsonRequestBehavior.AllowGet);
}
public static long GetIDCity( string contri, string citi)
{
使用(SportContext db = new SportContext())
{
long Idcontri = db.tbl_country.FirstOrDefault(p = > p.country ==重大贡献).ID;
return db.tbl_city.FirstOrDefault(p = > p.id_ country == Idcontri && p.city == citi).id;
}
}
解决方案
.ajax无效。并显示错误。
< script type = text / javascript>
{
( document )。ready(函数(){
alert(' hi');
(' #CountryAndCity')。change( function (){
var str = document .getElementById(' CountryAndCity')。value;
< span class =code-keyword> var str1 = str.split( ,, 1 )。toString();
var str2 = str.split( ,, 2 )。toString();
why $.ajax dose n't work . and show error .
<script type="text/javascript" >
{
$(document).ready(function () {
alert('hi');
$('#CountryAndCity ').change(function () {
var str = document.getElementById(' CountryAndCity ').value;
var str1 = str.split(", ", 1).toString();
var str2 = str.split(", ", 2).toString();
$.ajax({
url: '/AccountController/Myaction',
data: { countryy: str1, cityy: str2 },
cache: false,
type: 'GET',
success: function (result) {
$('hidMyModelid_city').val(result);
},
error: function (xhr, ajaxOptions, thrownError) {
alert(thrownError);
},
});
})
});
}
</script
public ActionResult MyAction(string countryy, string cityy)
{
var result = MyClass.GetIDCity(countryy, cityy);
return Json(result, JsonRequestBehavior.AllowGet);
}
public static long GetIDCity (string contri, string citi)
{
using(SportContext db = new SportContext ())
{
long Idcontri= db.tbl_country.FirstOrDefault(p => p.country == contri).id;
return db.tbl_city.FirstOrDefault(p => p.id_ country == Idcontri && p.city == citi).id;
}
}
解决方案
.ajax dose n't work . and show error .
<script type="text/javascript" > {
(document).ready(function () { alert('hi');
('#CountryAndCity ').change(function () { var str = document.getElementById(' CountryAndCity ').value; var str1 = str.split(", ", 1).toString(); var str2 = str.split(", ", 2).toString();
这篇关于为什么ajax不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文