如何从甜蜜警报的文本框中获取价值

问题描述

我想创建一个按钮,当单击它时,将弹出甜蜜警报,并且其中有文本框,我想获取文本框的值,然后通过ajax将其发送到我的Action中,发生? 像下面的代码

$("btn").click(function(){
  swal({
     title:'Please text the number',text:'You can text more than one',content:"input",showcancelbutton:'true',button{
        text:"Search"    
     }
  }),function(InputData)
    {
       if(InputData === ""){
      swal('Error','You Need To Write Something','error')
    }
   $.ajax({
      url:@Url.action("MyActionName","MyControllerName"),method:"Post",data: InputData
})
    }
})

这是我在这里的第一篇文章,非常感谢

解决方法

我从swal网站获得了一个完整的示例。遵循相同的步骤,您会得到它:

swal({
  text: 'Search for a movie. e.g. "La La Land".',content: "input",button: {
    text: "Search!",closeModal: false,},})
.then(name => {
  if (!name) throw null;
 
  return fetch(`https://itunes.apple.com/search?term=${name}&entity=movie`);
})
.then(results => {
  return results.json();
})
.then(json => {
  const movie = json.results[0];
 
  if (!movie) {
    return swal("No movie was found!");
  }
 
  const name = movie.trackName;
  const imageURL = movie.artworkUrl100;
 
  swal({
    title: "Top result:",text: name,icon: imageURL,});
})
.catch(err => {
  if (err) {
    swal("Oh noes!","The AJAX request failed!","error");
  } else {
    swal.stopLoading();
    swal.close();
  }
});

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...